From d25341d58de796545dcb3b0a620698b84a93b192 Mon Sep 17 00:00:00 2001 From: Ben Wells Date: Sun, 17 Dec 2017 13:55:20 +0000 Subject: [PATCH] Output models for go-server #3851 (#7188) * Output swagger models. Fix route verbs and formatting * Remove backup files * Make postProcessOperations consistent with go client --- .../codegen/languages/GoServerCodegen.java | 296 ++++++- .../src/main/resources/go-server/app.mustache | 1 - ...oller.mustache => controller-api.mustache} | 6 +- .../main/resources/go-server/logger.mustache | 1 + .../main/resources/go-server/main.mustache | 1 + .../main/resources/go-server/model.mustache | 24 + .../go-server/partial_header.mustache | 17 + .../main/resources/go-server/routers.mustache | 4 +- .../petstore/go-api-server/api/swagger.yaml | 780 ++++++++++++++++++ .../petstore/go-api-server/go/README.md | 2 +- .../petstore/go-api-server/go/api_response.go | 21 + .../server/petstore/go-api-server/go/app.yaml | 1 - .../petstore/go-api-server/go/category.go | 19 + .../petstore/go-api-server/go/logger.go | 10 + .../server/petstore/go-api-server/go/order.go | 32 + .../server/petstore/go-api-server/go/pet.go | 56 +- .../petstore/go-api-server/go/pet_api.go | 55 ++ .../petstore/go-api-server/go/routers.go | 51 +- .../go/{store.go => store_api.go} | 13 +- .../server/petstore/go-api-server/go/tag.go | 19 + .../server/petstore/go-api-server/go/user.go | 56 +- .../petstore/go-api-server/go/user_api.go | 55 ++ samples/server/petstore/go-api-server/main.go | 10 + 23 files changed, 1380 insertions(+), 150 deletions(-) delete mode 100644 modules/swagger-codegen/src/main/resources/go-server/app.mustache rename modules/swagger-codegen/src/main/resources/go-server/{controller.mustache => controller-api.mustache} (84%) create mode 100644 modules/swagger-codegen/src/main/resources/go-server/model.mustache create mode 100644 modules/swagger-codegen/src/main/resources/go-server/partial_header.mustache create mode 100644 samples/server/petstore/go-api-server/go/api_response.go delete mode 100644 samples/server/petstore/go-api-server/go/app.yaml create mode 100644 samples/server/petstore/go-api-server/go/category.go create mode 100644 samples/server/petstore/go-api-server/go/order.go create mode 100644 samples/server/petstore/go-api-server/go/pet_api.go rename samples/server/petstore/go-api-server/go/{store.go => store_api.go} (60%) create mode 100644 samples/server/petstore/go-api-server/go/tag.go create mode 100644 samples/server/petstore/go-api-server/go/user_api.go diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/GoServerCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/GoServerCodegen.java index 8fd49394be4..4829cd11b8d 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/GoServerCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/GoServerCodegen.java @@ -30,6 +30,7 @@ public class GoServerCodegen extends DefaultCodegen implements CodegenConfig { private static final Logger LOGGER = LoggerFactory.getLogger(GoServerCodegen.class); + protected String packageName = "swagger"; protected String apiVersion = "1.0.0"; protected int serverPort = 8080; protected String projectName = "swagger-server"; @@ -47,7 +48,9 @@ public class GoServerCodegen extends DefaultCodegen implements CodegenConfig { * for multiple files for model, just put another entry in the `modelTemplateFiles` with * a different extension */ - modelTemplateFiles.clear(); + modelTemplateFiles.put( + "model.mustache", + ".go"); /* * Api classes. You can write classes for each Api file with the apiTemplateFiles map. @@ -55,7 +58,7 @@ public class GoServerCodegen extends DefaultCodegen implements CodegenConfig { * class */ apiTemplateFiles.put( - "controller.mustache", // the template to use + "controller-api.mustache", // the template to use ".go"); // the extension for each file to write /* @@ -78,8 +81,7 @@ public class GoServerCodegen extends DefaultCodegen implements CodegenConfig { "case", "defer", "go", "map", "struct", "chan", "else", "goto", "package", "switch", "const", "fallthrough", "if", "range", "type", - "continue", "for", "import", "return", "var", "error", "ApiResponse", - "nil") + "continue", "for", "import", "return", "var", "error", "nil") // Added "error" as it's used so frequently that it may as well be a keyword ); @@ -143,6 +145,19 @@ public class GoServerCodegen extends DefaultCodegen implements CodegenConfig { cliOptions.add(new CliOption(CodegenConstants.HIDE_GENERATION_TIMESTAMP, "hides the timestamp when files were generated") .defaultValue(Boolean.TRUE.toString())); + } + + @Override + public void processOpts() { + super.processOpts(); + + if (additionalProperties.containsKey(CodegenConstants.PACKAGE_NAME)) { + setPackageName((String) additionalProperties.get(CodegenConstants.PACKAGE_NAME)); + } + else { + setPackageName("swagger"); + } + /* * Additional Properties. These values can be passed to the templates and * are available in models, apis, and supporting files @@ -150,19 +165,20 @@ public class GoServerCodegen extends DefaultCodegen implements CodegenConfig { additionalProperties.put("apiVersion", apiVersion); additionalProperties.put("serverPort", serverPort); additionalProperties.put("apiPath", apiPath); + additionalProperties.put(CodegenConstants.PACKAGE_NAME, packageName); + + modelPackage = packageName; + apiPackage = packageName; + /* * Supporting Files. You can write single files for the generator with the * entire object tree available. If the input file has a suffix of `.mustache * it will be processed by the template engine. Otherwise, it will be copied */ - supportingFiles.add(new SupportingFile("swagger.mustache", - "api", - "swagger.yaml") - ); + supportingFiles.add(new SupportingFile("swagger.mustache", "api", "swagger.yaml")); supportingFiles.add(new SupportingFile("main.mustache", "", "main.go")); supportingFiles.add(new SupportingFile("routers.mustache", apiPath, "routers.go")); supportingFiles.add(new SupportingFile("logger.mustache", apiPath, "logger.go")); - supportingFiles.add(new SupportingFile("app.mustache", apiPath, "app.yaml")); writeOptional(outputFolder, new SupportingFile("README.mustache", apiPath, "README.md")); } @@ -205,14 +221,6 @@ public class GoServerCodegen extends DefaultCodegen implements CodegenConfig { "it will also generate service classes--which you can disable with the `-Dnoservice` environment variable."; } - @Override - public String toApiName(String name) { - if (name.length() == 0) { - return "DefaultController"; - } - return initialCaps(name); - } - /** * Escapes a reserved word as defined in the `reservedWords` array. Handle escaping * those terms here. This logic is only called if a variable matches the reserved words @@ -220,11 +228,23 @@ public class GoServerCodegen extends DefaultCodegen implements CodegenConfig { * @return the escaped term */ @Override - public String escapeReservedWord(String name) { + public String escapeReservedWord(String name) + { + // Can't start with an underscore, as our fields need to start with an + // UppercaseLetter so that Go treats them as public/visible. + + // Options? + // - MyName + // - AName + // - TheName + // - XName + // - X_Name + // ... or maybe a suffix? + // - Name_ ... think this will work. if(this.reservedWordsMappings().containsKey(name)) { return this.reservedWordsMappings().get(name); } - return "_" + name; // add an underscore to the name + return camelize(name) + '_'; } /** @@ -236,6 +256,46 @@ public class GoServerCodegen extends DefaultCodegen implements CodegenConfig { return outputFolder + File.separator + apiPackage().replace('.', File.separatorChar); } + @Override + public String modelFileFolder() { + return outputFolder + File.separator + apiPackage().replace('.', File.separatorChar); + } + + @Override + public String toVarName(String name) { + // replace - with _ e.g. created-at => created_at + name = sanitizeName(name.replaceAll("-", "_")); + + // if it's all uppper case, do nothing + if (name.matches("^[A-Z_]*$")) + return name; + + // camelize (lower first character) the variable name + // pet_id => PetId + name = camelize(name); + + // for reserved word or word starting with number, append _ + if (isReservedWord(name)) + name = escapeReservedWord(name); + + // for reserved word or word starting with number, append _ + if (name.matches("^\\d.*")) + name = "Var" + name; + + return name; + } + + @Override + public String toParamName(String name) { + // params should be lowerCamelCase. E.g. "person Person", instead of + // "Person Person". + // + // REVISIT: Actually, for idiomatic go, the param name should + // really should just be a letter, e.g. "p Person"), but we'll get + // around to that some other time... Maybe. + return camelize(toVarName(name), true); + } + @Override public String toModelName(String name) { // camelize the model name @@ -243,36 +303,67 @@ public class GoServerCodegen extends DefaultCodegen implements CodegenConfig { return camelize(toModelFilename(name)); } - @Override - public String toOperationId(String operationId) { - // method name cannot use reserved keyword, e.g. return - if (isReservedWord(operationId)) { - LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + camelize(sanitizeName("call_" + operationId))); - operationId = "call_" + operationId; - } - - return camelize(operationId); - } - @Override public String toModelFilename(String name) { if (!StringUtils.isEmpty(modelNamePrefix)) { - name = modelNamePrefix + name; + name = modelNamePrefix + "_" + name; } if (!StringUtils.isEmpty(modelNameSuffix)) { - name = name + modelNameSuffix; + name = name + "_" + modelNameSuffix; } name = sanitizeName(name); // model name cannot use reserved keyword, e.g. return if (isReservedWord(name)) { - LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + camelize("model_" + name)); + LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + ("model_" + name)); name = "model_" + name; // e.g. return => ModelReturn (after camelize) } - return camelize(name); + // model name starts with number + if (name.matches("^\\d.*")) { + LOGGER.warn(name + " (model name starts with number) cannot be used as model name. Renamed to " + ("model_" + name)); + name = "model_" + name; // e.g. 200Response => Model200Response (after camelize) + } + + return underscore(name); + } + + @Override + public String toApiFilename(String name) { + // replace - with _ e.g. created-at => created_at + name = name.replaceAll("-", "_"); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'. + + // e.g. PetApi.go => pet_api.go + return underscore(name) + "_api"; + } + + /** + * Overrides postProcessParameter to add a vendor extension "x-exportParamName". + * This is useful when paramName starts with a lowercase letter, but we need that + * param to be exportable (starts with an Uppercase letter). + * + * @param parameter CodegenParameter object to be processed. + */ + @Override + public void postProcessParameter(CodegenParameter parameter){ + + // Give the base class a chance to process + super.postProcessParameter(parameter); + + char firstChar = parameter.paramName.charAt(0); + + if (Character.isUpperCase(firstChar)) { + // First char is already uppercase, just use paramName. + parameter.vendorExtensions.put("x-exportParamName", parameter.paramName); + + } + + // It's a lowercase first char, let's convert it to uppercase + StringBuilder sb = new StringBuilder(parameter.paramName); + sb.setCharAt(0, Character.toUpperCase(firstChar)); + parameter.vendorExtensions.put("x-exportParamName", sb.toString()); } @Override @@ -323,14 +414,127 @@ public class GoServerCodegen extends DefaultCodegen implements CodegenConfig { } @Override - public String toApiFilename(String name) { - // replace - with _ e.g. created-at => created_at - name = name.replaceAll("-", "_"); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'. + public String toOperationId(String operationId) { + String sanitizedOperationId = sanitizeName(operationId); - // e.g. PetApi.go => pet_api.go - return underscore(name); + // method name cannot use reserved keyword, e.g. return + if (isReservedWord(sanitizedOperationId)) { + LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + camelize("call_" + operationId)); + sanitizedOperationId = "call_" + sanitizedOperationId; + } + + return camelize(sanitizedOperationId); } + @Override + public Map postProcessOperations(Map objs) { + @SuppressWarnings("unchecked") + Map objectMap = (Map) objs.get("operations"); + @SuppressWarnings("unchecked") + List operations = (List) objectMap.get("operation"); + for (CodegenOperation operation : operations) { + // http method verb conversion (e.g. PUT => Put) + operation.httpMethod = camelize(operation.httpMethod.toLowerCase()); + } + + // remove model imports to avoid error + List> imports = (List>) objs.get("imports"); + if (imports == null) + return objs; + + Iterator> iterator = imports.iterator(); + while (iterator.hasNext()) { + String _import = iterator.next().get("import"); + if (_import.startsWith(apiPackage())) + iterator.remove(); + } + + // if their is a return type, import encoding/json + for (CodegenOperation operation : operations) { + if(operation.returnBaseType != null ) { + imports.add(createMapping("import", "encoding/json")); + break; //just need to import once + } + } + + // this will only import "fmt" if there are items in pathParams + for (CodegenOperation operation : operations) { + if(operation.pathParams != null && operation.pathParams.size() > 0) { + imports.add(createMapping("import", "fmt")); + break; //just need to import once + } + } + + // recursively add import for mapping one type to multiple imports + List> recursiveImports = (List>) objs.get("imports"); + if (recursiveImports == null) + return objs; + + ListIterator> listIterator = imports.listIterator(); + while (listIterator.hasNext()) { + String _import = listIterator.next().get("import"); + // if the import package happens to be found in the importMapping (key) + // add the corresponding import package to the list + if (importMapping.containsKey(_import)) { + listIterator.add(createMapping("import", importMapping.get(_import))); + } + } + + return objs; + } + + @Override + public Map postProcessSupportingFileData(Map objs) { + Swagger swagger = (Swagger)objs.get("swagger"); + if(swagger != null) { + try { + objs.put("swagger-yaml", Yaml.mapper().writeValueAsString(swagger)); + } catch (JsonProcessingException e) { + LOGGER.error(e.getMessage(), e); + } + } + return super.postProcessSupportingFileData(objs); + } + + @Override + public Map postProcessModels(Map objs) { + // remove model imports to avoid error + List> imports = (List>) objs.get("imports"); + final String prefix = modelPackage(); + Iterator> iterator = imports.iterator(); + while (iterator.hasNext()) { + String _import = iterator.next().get("import"); + if (_import.startsWith(prefix)) + iterator.remove(); + } + + // recursively add import for mapping one type to multiple imports + List> recursiveImports = (List>) objs.get("imports"); + if (recursiveImports == null) + return objs; + + ListIterator> listIterator = imports.listIterator(); + while (listIterator.hasNext()) { + String _import = listIterator.next().get("import"); + // if the import package happens to be found in the importMapping (key) + // add the corresponding import package to the list + if (importMapping.containsKey(_import)) { + listIterator.add(createMapping("import", importMapping.get(_import))); + } + } + + return postProcessModelsEnum(objs); + } + + @Override + protected boolean needToImport(String type) { + return !defaultIncludes.contains(type) + && !languageSpecificPrimitives.contains(type); + } + + public void setPackageName(String packageName) { + this.packageName = packageName; + } @Override public String escapeQuotationMark(String input) { // remove " to avoid code injection @@ -342,12 +546,19 @@ public class GoServerCodegen extends DefaultCodegen implements CodegenConfig { return input.replace("*/", "*_/").replace("/*", "/_*"); } + public Map createMapping(String key, String value){ + Map customImport = new HashMap(); + customImport.put(key, value); + + return customImport; + } + @Override public String toEnumValue(String value, String datatype) { if ("int".equals(datatype) || "double".equals(datatype) || "float".equals(datatype)) { return value; } else { - return "\'" + escapeText(value) + "\'"; + return escapeText(value); } } @@ -402,9 +613,4 @@ public class GoServerCodegen extends DefaultCodegen implements CodegenConfig { } } - @Override - public Map postProcessModels(Map objs) { - // process enum in models - return postProcessModelsEnum(objs); - } } diff --git a/modules/swagger-codegen/src/main/resources/go-server/app.mustache b/modules/swagger-codegen/src/main/resources/go-server/app.mustache deleted file mode 100644 index 18774a8cd31..00000000000 --- a/modules/swagger-codegen/src/main/resources/go-server/app.mustache +++ /dev/null @@ -1 +0,0 @@ -application: {{packageName}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/go-server/controller.mustache b/modules/swagger-codegen/src/main/resources/go-server/controller-api.mustache similarity index 84% rename from modules/swagger-codegen/src/main/resources/go-server/controller.mustache rename to modules/swagger-codegen/src/main/resources/go-server/controller-api.mustache index 4e91e4e1f3d..528e71fa21c 100644 --- a/modules/swagger-codegen/src/main/resources/go-server/controller.mustache +++ b/modules/swagger-codegen/src/main/resources/go-server/controller-api.mustache @@ -1,12 +1,10 @@ +{{>partial_header}} package {{packageName}} {{#operations}} import ( "net/http" -) - -type {{classname}} struct { -}{{#operation}} +){{#operation}} func {{nickname}}(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json; charset=UTF-8") diff --git a/modules/swagger-codegen/src/main/resources/go-server/logger.mustache b/modules/swagger-codegen/src/main/resources/go-server/logger.mustache index 8c636b477ba..aa0d894d83a 100644 --- a/modules/swagger-codegen/src/main/resources/go-server/logger.mustache +++ b/modules/swagger-codegen/src/main/resources/go-server/logger.mustache @@ -1,3 +1,4 @@ +{{>partial_header}} package {{packageName}} import ( diff --git a/modules/swagger-codegen/src/main/resources/go-server/main.mustache b/modules/swagger-codegen/src/main/resources/go-server/main.mustache index 749125b7e3e..28eb8861b1c 100644 --- a/modules/swagger-codegen/src/main/resources/go-server/main.mustache +++ b/modules/swagger-codegen/src/main/resources/go-server/main.mustache @@ -1,3 +1,4 @@ +{{>partial_header}} package main import ( diff --git a/modules/swagger-codegen/src/main/resources/go-server/model.mustache b/modules/swagger-codegen/src/main/resources/go-server/model.mustache new file mode 100644 index 00000000000..7c9e5c88aab --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/go-server/model.mustache @@ -0,0 +1,24 @@ +{{>partial_header}} +package {{packageName}} +{{#models}}{{#imports}} +import ({{/imports}}{{#imports}} + "{{import}}"{{/imports}}{{#imports}} +) +{{/imports}}{{#model}}{{#isEnum}}{{#description}}// {{{classname}}} : {{{description}}}{{/description}} +type {{{name}}} {{^format}}{{dataType}}{{/format}}{{#format}}{{{format}}}{{/format}} + +// List of {{{name}}} +const ( + {{#allowableValues}} + {{#enumVars}} + {{name}} {{{classname}}} = "{{{value}}}" + {{/enumVars}} + {{/allowableValues}} +){{/isEnum}}{{^isEnum}}{{#description}} +// {{{description}}}{{/description}} +type {{classname}} struct { +{{#vars}}{{#description}} + // {{{description}}}{{/description}} + {{name}} {{^isEnum}}{{^isPrimitiveType}}{{^isContainer}}{{^isDateTime}}*{{/isDateTime}}{{/isContainer}}{{/isPrimitiveType}}{{/isEnum}}{{{datatype}}} `json:"{{baseName}}{{^required}},omitempty{{/required}}"` +{{/vars}} +}{{/isEnum}}{{/model}}{{/models}} diff --git a/modules/swagger-codegen/src/main/resources/go-server/partial_header.mustache b/modules/swagger-codegen/src/main/resources/go-server/partial_header.mustache new file mode 100644 index 00000000000..d24dfec369d --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/go-server/partial_header.mustache @@ -0,0 +1,17 @@ +/* + {{#appName}} + * {{{appName}}} + * + {{/appName}} + {{#appDescription}} + * {{{appDescription}}} + * + {{/appDescription}} + {{#version}} + * API version: {{{version}}} + {{/version}} + {{#infoEmail}} + * Contact: {{{infoEmail}}} + {{/infoEmail}} + * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) + */ diff --git a/modules/swagger-codegen/src/main/resources/go-server/routers.mustache b/modules/swagger-codegen/src/main/resources/go-server/routers.mustache index d63544f1d8e..e3f5bdf3455 100644 --- a/modules/swagger-codegen/src/main/resources/go-server/routers.mustache +++ b/modules/swagger-codegen/src/main/resources/go-server/routers.mustache @@ -1,8 +1,10 @@ +{{>partial_header}} package {{packageName}} import ( "fmt" "net/http" + "strings" "github.com/gorilla/mux" ) @@ -47,7 +49,7 @@ var routes = Routes{ Route{ "{{operationId}}", - "{{httpMethod}}", + strings.ToUpper("{{httpMethod}}"), "{{{basePathWithoutHost}}}{{{path}}}", {{operationId}}, },{{/operation}}{{/operations}}{{/apis}}{{/apiInfo}} diff --git a/samples/server/petstore/go-api-server/api/swagger.yaml b/samples/server/petstore/go-api-server/api/swagger.yaml index e69de29bb2d..99a9cced9fa 100644 --- a/samples/server/petstore/go-api-server/api/swagger.yaml +++ b/samples/server/petstore/go-api-server/api/swagger.yaml @@ -0,0 +1,780 @@ +--- +swagger: "2.0" +info: + description: "This is a sample server Petstore server. You can find out more about\ + \ Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/).\ + \ For this sample, you can use the api key `special-key` to test the authorization\ + \ filters." + version: "1.0.0" + title: "Swagger Petstore" + termsOfService: "http://swagger.io/terms/" + contact: + email: "apiteam@swagger.io" + license: + name: "Apache-2.0" + url: "http://www.apache.org/licenses/LICENSE-2.0.html" +host: "petstore.swagger.io" +basePath: "/v2" +tags: +- name: "pet" + description: "Everything about your Pets" + externalDocs: + description: "Find out more" + url: "http://swagger.io" +- name: "store" + description: "Access to Petstore orders" +- name: "user" + description: "Operations about user" + externalDocs: + description: "Find out more about our store" + url: "http://swagger.io" +schemes: +- "http" +paths: + /pet: + post: + tags: + - "pet" + summary: "Add a new pet to the store" + description: "" + operationId: "addPet" + consumes: + - "application/json" + - "application/xml" + produces: + - "application/xml" + - "application/json" + parameters: + - in: "body" + name: "body" + description: "Pet object that needs to be added to the store" + required: true + schema: + $ref: "#/definitions/Pet" + x-exportParamName: "Body" + responses: + 405: + description: "Invalid input" + security: + - petstore_auth: + - "write:pets" + - "read:pets" + put: + tags: + - "pet" + summary: "Update an existing pet" + description: "" + operationId: "updatePet" + consumes: + - "application/json" + - "application/xml" + produces: + - "application/xml" + - "application/json" + parameters: + - in: "body" + name: "body" + description: "Pet object that needs to be added to the store" + required: true + schema: + $ref: "#/definitions/Pet" + x-exportParamName: "Body" + responses: + 400: + description: "Invalid ID supplied" + 404: + description: "Pet not found" + 405: + description: "Validation exception" + security: + - petstore_auth: + - "write:pets" + - "read:pets" + /pet/findByStatus: + get: + tags: + - "pet" + summary: "Finds Pets by status" + description: "Multiple status values can be provided with comma separated strings" + operationId: "findPetsByStatus" + produces: + - "application/xml" + - "application/json" + parameters: + - name: "status" + in: "query" + description: "Status values that need to be considered for filter" + required: true + type: "array" + items: + type: "string" + default: "available" + enum: + - "available" + - "pending" + - "sold" + collectionFormat: "csv" + x-exportParamName: "Status" + responses: + 200: + description: "successful operation" + schema: + type: "array" + items: + $ref: "#/definitions/Pet" + 400: + description: "Invalid status value" + security: + - petstore_auth: + - "write:pets" + - "read:pets" + /pet/findByTags: + get: + tags: + - "pet" + summary: "Finds Pets by tags" + description: "Multiple tags can be provided with comma separated strings. Use\ + \ tag1, tag2, tag3 for testing." + operationId: "findPetsByTags" + produces: + - "application/xml" + - "application/json" + parameters: + - name: "tags" + in: "query" + description: "Tags to filter by" + required: true + type: "array" + items: + type: "string" + collectionFormat: "csv" + x-exportParamName: "Tags" + responses: + 200: + description: "successful operation" + schema: + type: "array" + items: + $ref: "#/definitions/Pet" + 400: + description: "Invalid tag value" + security: + - petstore_auth: + - "write:pets" + - "read:pets" + deprecated: true + /pet/{petId}: + get: + tags: + - "pet" + summary: "Find pet by ID" + description: "Returns a single pet" + operationId: "getPetById" + produces: + - "application/xml" + - "application/json" + parameters: + - name: "petId" + in: "path" + description: "ID of pet to return" + required: true + type: "integer" + format: "int64" + x-exportParamName: "PetId" + responses: + 200: + description: "successful operation" + schema: + $ref: "#/definitions/Pet" + 400: + description: "Invalid ID supplied" + 404: + description: "Pet not found" + security: + - api_key: [] + post: + tags: + - "pet" + summary: "Updates a pet in the store with form data" + description: "" + operationId: "updatePetWithForm" + consumes: + - "application/x-www-form-urlencoded" + produces: + - "application/xml" + - "application/json" + parameters: + - name: "petId" + in: "path" + description: "ID of pet that needs to be updated" + required: true + type: "integer" + format: "int64" + x-exportParamName: "PetId" + - name: "name" + in: "formData" + description: "Updated name of the pet" + required: false + type: "string" + x-exportParamName: "Name" + - name: "status" + in: "formData" + description: "Updated status of the pet" + required: false + type: "string" + x-exportParamName: "Status" + responses: + 405: + description: "Invalid input" + security: + - petstore_auth: + - "write:pets" + - "read:pets" + delete: + tags: + - "pet" + summary: "Deletes a pet" + description: "" + operationId: "deletePet" + produces: + - "application/xml" + - "application/json" + parameters: + - name: "api_key" + in: "header" + required: false + type: "string" + x-exportParamName: "ApiKey" + - name: "petId" + in: "path" + description: "Pet id to delete" + required: true + type: "integer" + format: "int64" + x-exportParamName: "PetId" + responses: + 400: + description: "Invalid pet value" + security: + - petstore_auth: + - "write:pets" + - "read:pets" + /pet/{petId}/uploadImage: + post: + tags: + - "pet" + summary: "uploads an image" + description: "" + operationId: "uploadFile" + consumes: + - "multipart/form-data" + produces: + - "application/json" + parameters: + - name: "petId" + in: "path" + description: "ID of pet to update" + required: true + type: "integer" + format: "int64" + x-exportParamName: "PetId" + - name: "additionalMetadata" + in: "formData" + description: "Additional data to pass to server" + required: false + type: "string" + x-exportParamName: "AdditionalMetadata" + - name: "file" + in: "formData" + description: "file to upload" + required: false + type: "file" + x-exportParamName: "File" + responses: + 200: + description: "successful operation" + schema: + $ref: "#/definitions/ApiResponse" + security: + - petstore_auth: + - "write:pets" + - "read:pets" + /store/inventory: + get: + tags: + - "store" + summary: "Returns pet inventories by status" + description: "Returns a map of status codes to quantities" + operationId: "getInventory" + produces: + - "application/json" + parameters: [] + responses: + 200: + description: "successful operation" + schema: + type: "object" + additionalProperties: + type: "integer" + format: "int32" + security: + - api_key: [] + /store/order: + post: + tags: + - "store" + summary: "Place an order for a pet" + description: "" + operationId: "placeOrder" + produces: + - "application/xml" + - "application/json" + parameters: + - in: "body" + name: "body" + description: "order placed for purchasing the pet" + required: true + schema: + $ref: "#/definitions/Order" + x-exportParamName: "Body" + responses: + 200: + description: "successful operation" + schema: + $ref: "#/definitions/Order" + 400: + description: "Invalid Order" + /store/order/{orderId}: + get: + tags: + - "store" + summary: "Find purchase order by ID" + description: "For valid response try integer IDs with value <= 5 or > 10. Other\ + \ values will generated exceptions" + operationId: "getOrderById" + produces: + - "application/xml" + - "application/json" + parameters: + - name: "orderId" + in: "path" + description: "ID of pet that needs to be fetched" + required: true + type: "integer" + maximum: 5 + minimum: 1 + format: "int64" + x-exportParamName: "OrderId" + responses: + 200: + description: "successful operation" + schema: + $ref: "#/definitions/Order" + 400: + description: "Invalid ID supplied" + 404: + description: "Order not found" + delete: + tags: + - "store" + summary: "Delete purchase order by ID" + description: "For valid response try integer IDs with value < 1000. Anything\ + \ above 1000 or nonintegers will generate API errors" + operationId: "deleteOrder" + produces: + - "application/xml" + - "application/json" + parameters: + - name: "orderId" + in: "path" + description: "ID of the order that needs to be deleted" + required: true + type: "string" + x-exportParamName: "OrderId" + responses: + 400: + description: "Invalid ID supplied" + 404: + description: "Order not found" + /user: + post: + tags: + - "user" + summary: "Create user" + description: "This can only be done by the logged in user." + operationId: "createUser" + produces: + - "application/xml" + - "application/json" + parameters: + - in: "body" + name: "body" + description: "Created user object" + required: true + schema: + $ref: "#/definitions/User" + x-exportParamName: "Body" + responses: + default: + description: "successful operation" + /user/createWithArray: + post: + tags: + - "user" + summary: "Creates list of users with given input array" + description: "" + operationId: "createUsersWithArrayInput" + produces: + - "application/xml" + - "application/json" + parameters: + - in: "body" + name: "body" + description: "List of user object" + required: true + schema: + type: "array" + items: + $ref: "#/definitions/User" + x-exportParamName: "Body" + responses: + default: + description: "successful operation" + /user/createWithList: + post: + tags: + - "user" + summary: "Creates list of users with given input array" + description: "" + operationId: "createUsersWithListInput" + produces: + - "application/xml" + - "application/json" + parameters: + - in: "body" + name: "body" + description: "List of user object" + required: true + schema: + type: "array" + items: + $ref: "#/definitions/User" + x-exportParamName: "Body" + responses: + default: + description: "successful operation" + /user/login: + get: + tags: + - "user" + summary: "Logs user into the system" + description: "" + operationId: "loginUser" + produces: + - "application/xml" + - "application/json" + parameters: + - name: "username" + in: "query" + description: "The user name for login" + required: true + type: "string" + x-exportParamName: "Username" + - name: "password" + in: "query" + description: "The password for login in clear text" + required: true + type: "string" + x-exportParamName: "Password" + responses: + 200: + description: "successful operation" + schema: + type: "string" + headers: + X-Rate-Limit: + type: "integer" + format: "int32" + description: "calls per hour allowed by the user" + X-Expires-After: + type: "string" + format: "date-time" + description: "date in UTC when toekn expires" + 400: + description: "Invalid username/password supplied" + /user/logout: + get: + tags: + - "user" + summary: "Logs out current logged in user session" + description: "" + operationId: "logoutUser" + produces: + - "application/xml" + - "application/json" + parameters: [] + responses: + default: + description: "successful operation" + /user/{username}: + get: + tags: + - "user" + summary: "Get user by user name" + description: "" + operationId: "getUserByName" + produces: + - "application/xml" + - "application/json" + parameters: + - name: "username" + in: "path" + description: "The name that needs to be fetched. Use user1 for testing. " + required: true + type: "string" + x-exportParamName: "Username" + responses: + 200: + description: "successful operation" + schema: + $ref: "#/definitions/User" + 400: + description: "Invalid username supplied" + 404: + description: "User not found" + put: + tags: + - "user" + summary: "Updated user" + description: "This can only be done by the logged in user." + operationId: "updateUser" + produces: + - "application/xml" + - "application/json" + parameters: + - name: "username" + in: "path" + description: "name that need to be deleted" + required: true + type: "string" + x-exportParamName: "Username" + - in: "body" + name: "body" + description: "Updated user object" + required: true + schema: + $ref: "#/definitions/User" + x-exportParamName: "Body" + responses: + 400: + description: "Invalid user supplied" + 404: + description: "User not found" + delete: + tags: + - "user" + summary: "Delete user" + description: "This can only be done by the logged in user." + operationId: "deleteUser" + produces: + - "application/xml" + - "application/json" + parameters: + - name: "username" + in: "path" + description: "The name that needs to be deleted" + required: true + type: "string" + x-exportParamName: "Username" + responses: + 400: + description: "Invalid username supplied" + 404: + description: "User not found" +securityDefinitions: + petstore_auth: + type: "oauth2" + authorizationUrl: "http://petstore.swagger.io/api/oauth/dialog" + flow: "implicit" + scopes: + write:pets: "modify pets in your account" + read:pets: "read your pets" + api_key: + type: "apiKey" + name: "api_key" + in: "header" +definitions: + Order: + type: "object" + properties: + id: + type: "integer" + format: "int64" + petId: + type: "integer" + format: "int64" + quantity: + type: "integer" + format: "int32" + shipDate: + type: "string" + format: "date-time" + status: + type: "string" + description: "Order Status" + enum: + - "placed" + - "approved" + - "delivered" + complete: + type: "boolean" + default: false + title: "Pet Order" + description: "An order for a pets from the pet store" + example: + petId: 6 + quantity: 1 + id: 0 + shipDate: "2000-01-23T04:56:07.000+00:00" + complete: false + status: "placed" + xml: + name: "Order" + Category: + type: "object" + properties: + id: + type: "integer" + format: "int64" + name: + type: "string" + title: "Pet catehgry" + description: "A category for a pet" + example: + name: "name" + id: 6 + xml: + name: "Category" + User: + type: "object" + properties: + id: + type: "integer" + format: "int64" + username: + type: "string" + firstName: + type: "string" + lastName: + type: "string" + email: + type: "string" + password: + type: "string" + phone: + type: "string" + userStatus: + type: "integer" + format: "int32" + description: "User Status" + title: "a User" + description: "A User who is purchasing from the pet store" + example: + firstName: "firstName" + lastName: "lastName" + password: "password" + userStatus: 6 + phone: "phone" + id: 0 + email: "email" + username: "username" + xml: + name: "User" + Tag: + type: "object" + properties: + id: + type: "integer" + format: "int64" + name: + type: "string" + title: "Pet Tag" + description: "A tag for a pet" + example: + name: "name" + id: 1 + xml: + name: "Tag" + Pet: + type: "object" + required: + - "name" + - "photoUrls" + properties: + id: + type: "integer" + format: "int64" + category: + $ref: "#/definitions/Category" + name: + type: "string" + example: "doggie" + photoUrls: + type: "array" + xml: + name: "photoUrl" + wrapped: true + items: + type: "string" + tags: + type: "array" + xml: + name: "tag" + wrapped: true + items: + $ref: "#/definitions/Tag" + status: + type: "string" + description: "pet status in the store" + enum: + - "available" + - "pending" + - "sold" + title: "a Pet" + description: "A pet for sale in the pet store" + example: + photoUrls: + - "photoUrls" + - "photoUrls" + name: "doggie" + id: 0 + category: + name: "name" + id: 6 + tags: + - name: "name" + id: 1 + - name: "name" + id: 1 + status: "available" + xml: + name: "Pet" + ApiResponse: + type: "object" + properties: + code: + type: "integer" + format: "int32" + type: + type: "string" + message: + type: "string" + title: "An uploaded response" + description: "Describes the result of uploading an image resource" + example: + code: 0 + type: "type" + message: "message" +externalDocs: + description: "Find out more about Swagger" + url: "http://swagger.io" diff --git a/samples/server/petstore/go-api-server/go/README.md b/samples/server/petstore/go-api-server/go/README.md index 507fdaef454..685bcc7c19e 100644 --- a/samples/server/petstore/go-api-server/go/README.md +++ b/samples/server/petstore/go-api-server/go/README.md @@ -13,7 +13,7 @@ To see how to make this your own, look here: [README](https://github.com/swagger-api/swagger-codegen/blob/master/README.md) - API version: 1.0.0 -- Build date: 2017-12-12T20:26:23.341Z +- Build date: 2017-12-17T09:38:04.917Z ### Running the server diff --git a/samples/server/petstore/go-api-server/go/api_response.go b/samples/server/petstore/go-api-server/go/api_response.go new file mode 100644 index 00000000000..d7cb2190f11 --- /dev/null +++ b/samples/server/petstore/go-api-server/go/api_response.go @@ -0,0 +1,21 @@ +/* + * Swagger Petstore + * + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * API version: 1.0.0 + * Contact: apiteam@swagger.io + * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) + */ + +package petstoreserver + +// Describes the result of uploading an image resource +type ApiResponse struct { + + Code int32 `json:"code,omitempty"` + + Type_ string `json:"type,omitempty"` + + Message string `json:"message,omitempty"` +} diff --git a/samples/server/petstore/go-api-server/go/app.yaml b/samples/server/petstore/go-api-server/go/app.yaml deleted file mode 100644 index ea684a7280a..00000000000 --- a/samples/server/petstore/go-api-server/go/app.yaml +++ /dev/null @@ -1 +0,0 @@ -application: petstoreserver \ No newline at end of file diff --git a/samples/server/petstore/go-api-server/go/category.go b/samples/server/petstore/go-api-server/go/category.go new file mode 100644 index 00000000000..242d9fecaf4 --- /dev/null +++ b/samples/server/petstore/go-api-server/go/category.go @@ -0,0 +1,19 @@ +/* + * Swagger Petstore + * + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * API version: 1.0.0 + * Contact: apiteam@swagger.io + * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) + */ + +package petstoreserver + +// A category for a pet +type Category struct { + + Id int64 `json:"id,omitempty"` + + Name string `json:"name,omitempty"` +} diff --git a/samples/server/petstore/go-api-server/go/logger.go b/samples/server/petstore/go-api-server/go/logger.go index d61efef2423..85786a66af1 100644 --- a/samples/server/petstore/go-api-server/go/logger.go +++ b/samples/server/petstore/go-api-server/go/logger.go @@ -1,3 +1,13 @@ +/* + * Swagger Petstore + * + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * API version: 1.0.0 + * Contact: apiteam@swagger.io + * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) + */ + package petstoreserver import ( diff --git a/samples/server/petstore/go-api-server/go/order.go b/samples/server/petstore/go-api-server/go/order.go new file mode 100644 index 00000000000..03d6624afe4 --- /dev/null +++ b/samples/server/petstore/go-api-server/go/order.go @@ -0,0 +1,32 @@ +/* + * Swagger Petstore + * + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * API version: 1.0.0 + * Contact: apiteam@swagger.io + * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) + */ + +package petstoreserver + +import ( + "time" +) + +// An order for a pets from the pet store +type Order struct { + + Id int64 `json:"id,omitempty"` + + PetId int64 `json:"petId,omitempty"` + + Quantity int32 `json:"quantity,omitempty"` + + ShipDate time.Time `json:"shipDate,omitempty"` + + // Order Status + Status string `json:"status,omitempty"` + + Complete bool `json:"complete,omitempty"` +} diff --git a/samples/server/petstore/go-api-server/go/pet.go b/samples/server/petstore/go-api-server/go/pet.go index a5c9a9375fd..756bacd9ac6 100644 --- a/samples/server/petstore/go-api-server/go/pet.go +++ b/samples/server/petstore/go-api-server/go/pet.go @@ -1,48 +1,28 @@ +/* + * Swagger Petstore + * + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * API version: 1.0.0 + * Contact: apiteam@swagger.io + * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) + */ + package petstoreserver -import ( - "net/http" -) - +// A pet for sale in the pet store type Pet struct { -} -func AddPet(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "application/json; charset=UTF-8") - w.WriteHeader(http.StatusOK) -} + Id int64 `json:"id,omitempty"` -func DeletePet(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "application/json; charset=UTF-8") - w.WriteHeader(http.StatusOK) -} + Category *Category `json:"category,omitempty"` -func FindPetsByStatus(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "application/json; charset=UTF-8") - w.WriteHeader(http.StatusOK) -} + Name string `json:"name"` -func FindPetsByTags(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "application/json; charset=UTF-8") - w.WriteHeader(http.StatusOK) -} + PhotoUrls []string `json:"photoUrls"` -func GetPetById(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "application/json; charset=UTF-8") - w.WriteHeader(http.StatusOK) -} + Tags []Tag `json:"tags,omitempty"` -func UpdatePet(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "application/json; charset=UTF-8") - w.WriteHeader(http.StatusOK) -} - -func UpdatePetWithForm(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "application/json; charset=UTF-8") - w.WriteHeader(http.StatusOK) -} - -func UploadFile(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "application/json; charset=UTF-8") - w.WriteHeader(http.StatusOK) + // pet status in the store + Status string `json:"status,omitempty"` } diff --git a/samples/server/petstore/go-api-server/go/pet_api.go b/samples/server/petstore/go-api-server/go/pet_api.go new file mode 100644 index 00000000000..d404489b227 --- /dev/null +++ b/samples/server/petstore/go-api-server/go/pet_api.go @@ -0,0 +1,55 @@ +/* + * Swagger Petstore + * + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * API version: 1.0.0 + * Contact: apiteam@swagger.io + * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) + */ + +package petstoreserver + +import ( + "net/http" +) + +func AddPet(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json; charset=UTF-8") + w.WriteHeader(http.StatusOK) +} + +func DeletePet(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json; charset=UTF-8") + w.WriteHeader(http.StatusOK) +} + +func FindPetsByStatus(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json; charset=UTF-8") + w.WriteHeader(http.StatusOK) +} + +func FindPetsByTags(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json; charset=UTF-8") + w.WriteHeader(http.StatusOK) +} + +func GetPetById(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json; charset=UTF-8") + w.WriteHeader(http.StatusOK) +} + +func UpdatePet(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json; charset=UTF-8") + w.WriteHeader(http.StatusOK) +} + +func UpdatePetWithForm(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json; charset=UTF-8") + w.WriteHeader(http.StatusOK) +} + +func UploadFile(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json; charset=UTF-8") + w.WriteHeader(http.StatusOK) +} diff --git a/samples/server/petstore/go-api-server/go/routers.go b/samples/server/petstore/go-api-server/go/routers.go index f0e3a29e527..af7d74c8ae7 100644 --- a/samples/server/petstore/go-api-server/go/routers.go +++ b/samples/server/petstore/go-api-server/go/routers.go @@ -1,8 +1,19 @@ +/* + * Swagger Petstore + * + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * API version: 1.0.0 + * Contact: apiteam@swagger.io + * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) + */ + package petstoreserver import ( "fmt" "net/http" + "strings" "github.com/gorilla/mux" ) @@ -47,140 +58,140 @@ var routes = Routes{ Route{ "AddPet", - "POST", + strings.ToUpper("Post"), "/v2/pet", AddPet, }, Route{ "DeletePet", - "DELETE", + strings.ToUpper("Delete"), "/v2/pet/{petId}", DeletePet, }, Route{ "FindPetsByStatus", - "GET", + strings.ToUpper("Get"), "/v2/pet/findByStatus", FindPetsByStatus, }, Route{ "FindPetsByTags", - "GET", + strings.ToUpper("Get"), "/v2/pet/findByTags", FindPetsByTags, }, Route{ "GetPetById", - "GET", + strings.ToUpper("Get"), "/v2/pet/{petId}", GetPetById, }, Route{ "UpdatePet", - "PUT", + strings.ToUpper("Put"), "/v2/pet", UpdatePet, }, Route{ "UpdatePetWithForm", - "POST", + strings.ToUpper("Post"), "/v2/pet/{petId}", UpdatePetWithForm, }, Route{ "UploadFile", - "POST", + strings.ToUpper("Post"), "/v2/pet/{petId}/uploadImage", UploadFile, }, Route{ "DeleteOrder", - "DELETE", + strings.ToUpper("Delete"), "/v2/store/order/{orderId}", DeleteOrder, }, Route{ "GetInventory", - "GET", + strings.ToUpper("Get"), "/v2/store/inventory", GetInventory, }, Route{ "GetOrderById", - "GET", + strings.ToUpper("Get"), "/v2/store/order/{orderId}", GetOrderById, }, Route{ "PlaceOrder", - "POST", + strings.ToUpper("Post"), "/v2/store/order", PlaceOrder, }, Route{ "CreateUser", - "POST", + strings.ToUpper("Post"), "/v2/user", CreateUser, }, Route{ "CreateUsersWithArrayInput", - "POST", + strings.ToUpper("Post"), "/v2/user/createWithArray", CreateUsersWithArrayInput, }, Route{ "CreateUsersWithListInput", - "POST", + strings.ToUpper("Post"), "/v2/user/createWithList", CreateUsersWithListInput, }, Route{ "DeleteUser", - "DELETE", + strings.ToUpper("Delete"), "/v2/user/{username}", DeleteUser, }, Route{ "GetUserByName", - "GET", + strings.ToUpper("Get"), "/v2/user/{username}", GetUserByName, }, Route{ "LoginUser", - "GET", + strings.ToUpper("Get"), "/v2/user/login", LoginUser, }, Route{ "LogoutUser", - "GET", + strings.ToUpper("Get"), "/v2/user/logout", LogoutUser, }, Route{ "UpdateUser", - "PUT", + strings.ToUpper("Put"), "/v2/user/{username}", UpdateUser, }, diff --git a/samples/server/petstore/go-api-server/go/store.go b/samples/server/petstore/go-api-server/go/store_api.go similarity index 60% rename from samples/server/petstore/go-api-server/go/store.go rename to samples/server/petstore/go-api-server/go/store_api.go index e48c9b5a2e2..6a80e4b27ac 100644 --- a/samples/server/petstore/go-api-server/go/store.go +++ b/samples/server/petstore/go-api-server/go/store_api.go @@ -1,12 +1,19 @@ +/* + * Swagger Petstore + * + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * API version: 1.0.0 + * Contact: apiteam@swagger.io + * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) + */ + package petstoreserver import ( "net/http" ) -type Store struct { -} - func DeleteOrder(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json; charset=UTF-8") w.WriteHeader(http.StatusOK) diff --git a/samples/server/petstore/go-api-server/go/tag.go b/samples/server/petstore/go-api-server/go/tag.go new file mode 100644 index 00000000000..455e39bf1ba --- /dev/null +++ b/samples/server/petstore/go-api-server/go/tag.go @@ -0,0 +1,19 @@ +/* + * Swagger Petstore + * + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * API version: 1.0.0 + * Contact: apiteam@swagger.io + * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) + */ + +package petstoreserver + +// A tag for a pet +type Tag struct { + + Id int64 `json:"id,omitempty"` + + Name string `json:"name,omitempty"` +} diff --git a/samples/server/petstore/go-api-server/go/user.go b/samples/server/petstore/go-api-server/go/user.go index 097a25e4dd8..124ba328c8d 100644 --- a/samples/server/petstore/go-api-server/go/user.go +++ b/samples/server/petstore/go-api-server/go/user.go @@ -1,48 +1,32 @@ +/* + * Swagger Petstore + * + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * API version: 1.0.0 + * Contact: apiteam@swagger.io + * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) + */ + package petstoreserver -import ( - "net/http" -) - +// A User who is purchasing from the pet store type User struct { -} -func CreateUser(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "application/json; charset=UTF-8") - w.WriteHeader(http.StatusOK) -} + Id int64 `json:"id,omitempty"` -func CreateUsersWithArrayInput(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "application/json; charset=UTF-8") - w.WriteHeader(http.StatusOK) -} + Username string `json:"username,omitempty"` -func CreateUsersWithListInput(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "application/json; charset=UTF-8") - w.WriteHeader(http.StatusOK) -} + FirstName string `json:"firstName,omitempty"` -func DeleteUser(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "application/json; charset=UTF-8") - w.WriteHeader(http.StatusOK) -} + LastName string `json:"lastName,omitempty"` -func GetUserByName(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "application/json; charset=UTF-8") - w.WriteHeader(http.StatusOK) -} + Email string `json:"email,omitempty"` -func LoginUser(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "application/json; charset=UTF-8") - w.WriteHeader(http.StatusOK) -} + Password string `json:"password,omitempty"` -func LogoutUser(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "application/json; charset=UTF-8") - w.WriteHeader(http.StatusOK) -} + Phone string `json:"phone,omitempty"` -func UpdateUser(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "application/json; charset=UTF-8") - w.WriteHeader(http.StatusOK) + // User Status + UserStatus int32 `json:"userStatus,omitempty"` } diff --git a/samples/server/petstore/go-api-server/go/user_api.go b/samples/server/petstore/go-api-server/go/user_api.go new file mode 100644 index 00000000000..2428aa56161 --- /dev/null +++ b/samples/server/petstore/go-api-server/go/user_api.go @@ -0,0 +1,55 @@ +/* + * Swagger Petstore + * + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * API version: 1.0.0 + * Contact: apiteam@swagger.io + * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) + */ + +package petstoreserver + +import ( + "net/http" +) + +func CreateUser(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json; charset=UTF-8") + w.WriteHeader(http.StatusOK) +} + +func CreateUsersWithArrayInput(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json; charset=UTF-8") + w.WriteHeader(http.StatusOK) +} + +func CreateUsersWithListInput(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json; charset=UTF-8") + w.WriteHeader(http.StatusOK) +} + +func DeleteUser(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json; charset=UTF-8") + w.WriteHeader(http.StatusOK) +} + +func GetUserByName(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json; charset=UTF-8") + w.WriteHeader(http.StatusOK) +} + +func LoginUser(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json; charset=UTF-8") + w.WriteHeader(http.StatusOK) +} + +func LogoutUser(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json; charset=UTF-8") + w.WriteHeader(http.StatusOK) +} + +func UpdateUser(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json; charset=UTF-8") + w.WriteHeader(http.StatusOK) +} diff --git a/samples/server/petstore/go-api-server/main.go b/samples/server/petstore/go-api-server/main.go index ed6c13a1eff..7597fe7465e 100644 --- a/samples/server/petstore/go-api-server/main.go +++ b/samples/server/petstore/go-api-server/main.go @@ -1,3 +1,13 @@ +/* + * Swagger Petstore + * + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * API version: 1.0.0 + * Contact: apiteam@swagger.io + * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) + */ + package main import (