diff --git a/bin/go-gin-petstore-server.sh b/bin/go-gin-petstore-server.sh index 6ad025fdb55e..7d83fc12b274 100755 --- a/bin/go-gin-petstore-server.sh +++ b/bin/go-gin-petstore-server.sh @@ -25,10 +25,17 @@ then mvn -B clean package fi +SPEC="modules/openapi-generator/src/test/resources/2_0/petstore.yaml" +GENERATOR="go-gin-server" +STUB_DIR="samples/server/petstore/go-gin-api-server" + +echo "Removing files and folders under $STUB_DIR" +rm -rf $STUB_DIR + # if you've executed sbt assembly previously it will use that instead. export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties" -ags="generate -t modules/openapi-generator/src/main/resources/go-gin-server -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g go-gin-server -o samples/server/petstore/go-gin-api-server -DpackageName=petstoreserver --additional-properties hideGenerationTimestamp=true -Dservice $@" +ags="generate -t modules/openapi-generator/src/main/resources/go-gin-server -i $SPEC -g $GENERATOR -o $STUB_DIR -DpackageName=petstoreserver --additional-properties hideGenerationTimestamp=true -Dservice $@" java $JAVA_OPTS -jar $executable $ags #!/usr/bin/env bash \ No newline at end of file diff --git a/bin/go-petstore-server.sh b/bin/go-petstore-server.sh index 430547dfea96..b2cc320b6487 100755 --- a/bin/go-petstore-server.sh +++ b/bin/go-petstore-server.sh @@ -25,9 +25,16 @@ then mvn -B clean package fi +SPEC="modules/openapi-generator/src/test/resources/2_0/petstore.yaml" +GENERATOR="go-server" +STUB_DIR="samples/server/petstore/go-api-server" + +echo "Removing files and folders under $STUB_DIR" +rm -rf $STUB_DIR + # if you've executed sbt assembly previously it will use that instead. export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties" -ags="generate -t modules/openapi-generator/src/main/resources/go-server -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g go-server -o samples/server/petstore/go-api-server -DpackageName=petstoreserver --additional-properties hideGenerationTimestamp=true -Dservice $@" +ags="generate -t modules/openapi-generator/src/main/resources/go-server -i $SPEC -g $GENERATOR -o $STUB_DIR -DpackageName=petstoreserver --additional-properties hideGenerationTimestamp=true -Dservice $@" java $JAVA_OPTS -jar $executable $ags diff --git a/bin/go-petstore-withxml.sh b/bin/go-petstore-withxml.sh index 222fd35cf2f6..8cb9c812e39a 100755 --- a/bin/go-petstore-withxml.sh +++ b/bin/go-petstore-withxml.sh @@ -25,11 +25,15 @@ then mvn -B clean package fi -echo "Removing files and folders under samples/client/petstore/go/go-petstore-withXml" -rm -rf samples/client/petstore/go/go-petstore-withXml +SPEC="modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml" +GENERATOR="go" +STUB_DIR="samples/client/petstore/go/go-petstore-withXml" + +echo "Removing files and folders under $STUB_DIR" +rm -rf $STUB_DIR # if you've executed sbt assembly previously it will use that instead. export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties" -ags="generate -t modules/openapi-generator/src/main/resources/go -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g go -o samples/client/petstore/go/go-petstore-withXml -DpackageName=petstore,withXml=true,withGoCodegenComment=true $@" +ags="generate -t modules/openapi-generator/src/main/resources/go -i $SPEC -g $GENERATOR -o $STUB_DIR -DpackageName=petstore,withXml=true,withGoCodegenComment=true $@" java $JAVA_OPTS -jar $executable $ags diff --git a/bin/go-petstore.sh b/bin/go-petstore.sh index 1ce6ab99656a..fa5a88d60925 100755 --- a/bin/go-petstore.sh +++ b/bin/go-petstore.sh @@ -25,11 +25,15 @@ then mvn -B clean package fi -echo "Removing files and folders under samples/client/petstore/go/go-petstore" -rm -rf samples/client/petstore/go/go-petstore +SPEC="modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml" +GENERATOR="go" +STUB_DIR="samples/client/petstore/go/go-petstore" + +echo "Removing files and folders under $STUB_DIR" +rm -rf $STUB_DIR # if you've executed sbt assembly previously it will use that instead. export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties" -ags="generate -t modules/openapi-generator/src/main/resources/go -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g go -o samples/client/petstore/go/go-petstore -DpackageName=petstore $@" +ags="generate -t modules/openapi-generator/src/main/resources/go -i $SPEC -g $GENERATOR -o $STUB_DIR -DpackageName=petstore $@" java $JAVA_OPTS -jar $executable $ags diff --git a/bin/openapi3/go-gin-petstore-server.sh b/bin/openapi3/go-gin-petstore-server.sh index 310cad7fe868..c2c1ee8f0fd1 100755 --- a/bin/openapi3/go-gin-petstore-server.sh +++ b/bin/openapi3/go-gin-petstore-server.sh @@ -25,10 +25,17 @@ then mvn -B clean package fi +SPEC="modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml" +GENERATOR="go-gin-server" +STUB_DIR="samples/openapi3/server/petstore/go-gin-api-server" + +echo "Removing files and folders under $STUB_DIR" +rm -rf $STUB_DIR + # if you've executed sbt assembly previously it will use that instead. export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties" -ags="generate -t modules/openapi-generator/src/main/resources/go-gin-server -i modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml -g go-gin-server -o samples/openapi3/server/petstore/go-gin-api-server -DpackageName=petstoreserver --additional-properties hideGenerationTimestamp=true -Dservice $@" +ags="generate -t modules/openapi-generator/src/main/resources/go-gin-server -i $SPEC -g $GENERATOR -o $STUB_DIR -DpackageName=petstoreserver --additional-properties hideGenerationTimestamp=true -Dservice $@" java $JAVA_OPTS -jar $executable $ags #!/usr/bin/env bash \ No newline at end of file diff --git a/bin/openapi3/go-petstore-server.sh b/bin/openapi3/go-petstore-server.sh index d14f19df0e4a..d510a171f9b1 100755 --- a/bin/openapi3/go-petstore-server.sh +++ b/bin/openapi3/go-petstore-server.sh @@ -25,9 +25,16 @@ then mvn clean package fi +SPEC="modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml" +GENERATOR="go-server" +STUB_DIR="samples/openapi3/server/petstore/go-api-server" + +echo "Removing files and folders under $STUB_DIR" +rm -rf $STUB_DIR + # if you've executed sbt assembly previously it will use that instead. export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties" -ags="generate -t modules/openapi-generator/src/main/resources/go-server -i modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml -g go-server -o samples/openapi3/server/petstore/go-api-server -DpackageName=petstoreserver --additional-properties hideGenerationTimestamp=true -Dservice $@" +ags="generate -t modules/openapi-generator/src/main/resources/go-server -i $SPEC -g $GENERATOR -o $STUB_DIR -DpackageName=petstoreserver --additional-properties hideGenerationTimestamp=true -Dservice $@" java $JAVA_OPTS -jar $executable $ags diff --git a/bin/openapi3/go-petstore.sh b/bin/openapi3/go-petstore.sh index db9630485d8b..e50e8a2d928c 100755 --- a/bin/openapi3/go-petstore.sh +++ b/bin/openapi3/go-petstore.sh @@ -28,6 +28,7 @@ fi SPEC="modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml" GENERATOR="go" STUB_DIR="samples/openapi3/client/petstore/go/go-petstore" + echo "Removing files and folders under $STUB_DIR" rm -rf $STUB_DIR diff --git a/bin/security/go-petstore.sh b/bin/security/go-petstore.sh index c141ef5e3385..67b2b5d7fd44 100755 --- a/bin/security/go-petstore.sh +++ b/bin/security/go-petstore.sh @@ -25,8 +25,15 @@ then mvn clean package fi +SPEC="modules/openapi-generator/src/test/resources/2_0/petstore-security-test.yaml" +GENERATOR="go" +STUB_DIR="samples/client/petstore-security-test/go" + +echo "Removing files and folders under $STUB_DIR" +rm -rf $STUB_DIR + # if you've executed sbt assembly previously it will use that instead. export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties" -ags="generate -t modules/openapi-generator/src/main/resources/go -i modules/openapi-generator/src/test/resources/2_0/petstore-security-test.yaml -g go -o samples/client/petstore-security-test/go $@" +ags="generate -t modules/openapi-generator/src/main/resources/go -i $SPEC -g $GENERATOR -o $STUB_DIR $@" java $JAVA_OPTS -jar $executable $ags diff --git a/samples/client/petstore-security-test/go/LICENSE b/samples/client/petstore-security-test/go/LICENSE deleted file mode 100644 index 8dada3edaf50..000000000000 --- a/samples/client/petstore-security-test/go/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "{}" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright {yyyy} {name of copyright owner} - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/samples/client/petstore-security-test/go/api_client.go b/samples/client/petstore-security-test/go/api_client.go deleted file mode 100644 index 7bff32624325..000000000000 --- a/samples/client/petstore-security-test/go/api_client.go +++ /dev/null @@ -1,426 +0,0 @@ -/* - * Swagger Petstore *_/ ' \" =end -- \\r\\n \\n \\r - * - * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ *_/ ' \" =end -- - * - * API version: 1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r - * Contact: apiteam@swagger.io *_/ ' \" =end -- \\r\\n \\n \\r - * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) - */ - -package swagger - -import ( - "bytes" - "encoding/json" - "encoding/xml" - "errors" - "fmt" - "io" - "mime/multipart" - "net/http" - "net/url" - "os" - "path/filepath" - "reflect" - "regexp" - "strconv" - "strings" - "time" - "unicode/utf8" - - "golang.org/x/net/context" - "golang.org/x/oauth2" -) - -var ( - jsonCheck = regexp.MustCompile("(?i:[application|text]/json)") - xmlCheck = regexp.MustCompile("(?i:[application|text]/xml)") -) - -// APIClient manages communication with the Swagger Petstore *_/ ' \" =end -- \\r\\n \\n \\r API v1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r -// In most cases there should be only one, shared, APIClient. -type APIClient struct { - cfg *Configuration - common service // Reuse a single struct instead of allocating one for each service on the heap. - - // API Services - - FakeApi *FakeApiService -} - -type service struct { - client *APIClient -} - -// NewAPIClient creates a new API client. Requires a userAgent string describing your application. -// optionally a custom http.Client to allow for advanced features such as caching. -func NewAPIClient(cfg *Configuration) *APIClient { - if cfg.HTTPClient == nil { - cfg.HTTPClient = http.DefaultClient - } - - c := &APIClient{} - c.cfg = cfg - c.common.client = c - - // API Services - c.FakeApi = (*FakeApiService)(&c.common) - - return c -} - -func atoi(in string) (int, error) { - return strconv.Atoi(in) -} - -// selectHeaderContentType select a content type from the available list. -func selectHeaderContentType(contentTypes []string) string { - if len(contentTypes) == 0 { - return "" - } - if contains(contentTypes, "application/json") { - return "application/json" - } - return contentTypes[0] // use the first content type specified in 'consumes' -} - -// selectHeaderAccept join all accept types and return -func selectHeaderAccept(accepts []string) string { - if len(accepts) == 0 { - return "" - } - - if contains(accepts, "application/json") { - return "application/json" - } - - return strings.Join(accepts, ",") -} - -// contains is a case insenstive match, finding needle in a haystack -func contains(haystack []string, needle string) bool { - for _, a := range haystack { - if strings.ToLower(a) == strings.ToLower(needle) { - return true - } - } - return false -} - -// Verify optional parameters are of the correct type. -func typeCheckParameter(obj interface{}, expected string, name string) error { - // Make sure there is an object. - if obj == nil { - return nil - } - - // Check the type is as expected. - if reflect.TypeOf(obj).String() != expected { - return fmt.Errorf("Expected %s to be of type %s but received %s.", name, expected, reflect.TypeOf(obj).String()) - } - return nil -} - -// parameterToString convert interface{} parameters to string, using a delimiter if format is provided. -func parameterToString(obj interface{}, collectionFormat string) string { - var delimiter string - - switch collectionFormat { - case "pipes": - delimiter = "|" - case "ssv": - delimiter = " " - case "tsv": - delimiter = "\t" - case "csv": - delimiter = "," - } - - if reflect.TypeOf(obj).Kind() == reflect.Slice { - return strings.Trim(strings.Replace(fmt.Sprint(obj), " ", delimiter, -1), "[]") - } - - return fmt.Sprintf("%v", obj) -} - -// callAPI do the request. -func (c *APIClient) callAPI(request *http.Request) (*http.Response, error) { - return c.cfg.HTTPClient.Do(request) -} - -// Change base path to allow switching to mocks -func (c *APIClient) ChangeBasePath(path string) { - c.cfg.BasePath = path -} - -// prepareRequest build the request -func (c *APIClient) prepareRequest( - ctx context.Context, - path string, method string, - postBody interface{}, - headerParams map[string]string, - queryParams url.Values, - formParams url.Values, - fileName string, - fileBytes []byte) (localVarRequest *http.Request, err error) { - - var body *bytes.Buffer - - // Detect postBody type and post. - if postBody != nil { - contentType := headerParams["Content-Type"] - if contentType == "" { - contentType = detectContentType(postBody) - headerParams["Content-Type"] = contentType - } - - body, err = setBody(postBody, contentType) - if err != nil { - return nil, err - } - } - - // add form parameters and file if available. - if len(formParams) > 0 || (len(fileBytes) > 0 && fileName != "") { - if body != nil { - return nil, errors.New("Cannot specify postBody and multipart form at the same time.") - } - body = &bytes.Buffer{} - w := multipart.NewWriter(body) - - for k, v := range formParams { - for _, iv := range v { - if strings.HasPrefix(k, "@") { // file - err = addFile(w, k[1:], iv) - if err != nil { - return nil, err - } - } else { // form value - w.WriteField(k, iv) - } - } - } - if len(fileBytes) > 0 && fileName != "" { - w.Boundary() - //_, fileNm := filepath.Split(fileName) - part, err := w.CreateFormFile("file", filepath.Base(fileName)) - if err != nil { - return nil, err - } - _, err = part.Write(fileBytes) - if err != nil { - return nil, err - } - // Set the Boundary in the Content-Type - headerParams["Content-Type"] = w.FormDataContentType() - } - - // Set Content-Length - headerParams["Content-Length"] = fmt.Sprintf("%d", body.Len()) - w.Close() - } - - // Setup path and query parameters - url, err := url.Parse(path) - if err != nil { - return nil, err - } - - // Adding Query Param - query := url.Query() - for k, v := range queryParams { - for _, iv := range v { - query.Add(k, iv) - } - } - - // Encode the parameters. - url.RawQuery = query.Encode() - - // Generate a new request - if body != nil { - localVarRequest, err = http.NewRequest(method, url.String(), body) - } else { - localVarRequest, err = http.NewRequest(method, url.String(), nil) - } - if err != nil { - return nil, err - } - - // add header parameters, if any - if len(headerParams) > 0 { - headers := http.Header{} - for h, v := range headerParams { - headers.Set(h, v) - } - localVarRequest.Header = headers - } - - // Override request host, if applicable - if c.cfg.Host != "" { - localVarRequest.Host = c.cfg.Host - } - - // Add the user agent to the request. - localVarRequest.Header.Add("User-Agent", c.cfg.UserAgent) - - if ctx != nil { - // add context to the request - localVarRequest = localVarRequest.WithContext(ctx) - - // Walk through any authentication. - - // OAuth2 authentication - if tok, ok := ctx.Value(ContextOAuth2).(oauth2.TokenSource); ok { - // We were able to grab an oauth2 token from the context - var latestToken *oauth2.Token - if latestToken, err = tok.Token(); err != nil { - return nil, err - } - - latestToken.SetAuthHeader(localVarRequest) - } - - // Basic HTTP Authentication - if auth, ok := ctx.Value(ContextBasicAuth).(BasicAuth); ok { - localVarRequest.SetBasicAuth(auth.UserName, auth.Password) - } - - // AccessToken Authentication - if auth, ok := ctx.Value(ContextAccessToken).(string); ok { - localVarRequest.Header.Add("Authorization", "Bearer "+auth) - } - } - - for header, value := range c.cfg.DefaultHeader { - localVarRequest.Header.Add(header, value) - } - - return localVarRequest, nil -} - -// Add a file to the multipart request -func addFile(w *multipart.Writer, fieldName, path string) error { - file, err := os.Open(path) - if err != nil { - return err - } - defer file.Close() - - part, err := w.CreateFormFile(fieldName, filepath.Base(path)) - if err != nil { - return err - } - _, err = io.Copy(part, file) - - return err -} - -// Prevent trying to import "fmt" -func reportError(format string, a ...interface{}) error { - return fmt.Errorf(format, a...) -} - -// Set request body from an interface{} -func setBody(body interface{}, contentType string) (bodyBuf *bytes.Buffer, err error) { - if bodyBuf == nil { - bodyBuf = &bytes.Buffer{} - } - - if reader, ok := body.(io.Reader); ok { - _, err = bodyBuf.ReadFrom(reader) - } else if b, ok := body.([]byte); ok { - _, err = bodyBuf.Write(b) - } else if s, ok := body.(string); ok { - _, err = bodyBuf.WriteString(s) - } else if jsonCheck.MatchString(contentType) { - err = json.NewEncoder(bodyBuf).Encode(body) - } else if xmlCheck.MatchString(contentType) { - xml.NewEncoder(bodyBuf).Encode(body) - } - - if err != nil { - return nil, err - } - - if bodyBuf.Len() == 0 { - err = fmt.Errorf("Invalid body type %s\n", contentType) - return nil, err - } - return bodyBuf, nil -} - -// detectContentType method is used to figure out `Request.Body` content type for request header -func detectContentType(body interface{}) string { - contentType := "text/plain; charset=utf-8" - kind := reflect.TypeOf(body).Kind() - - switch kind { - case reflect.Struct, reflect.Map, reflect.Ptr: - contentType = "application/json; charset=utf-8" - case reflect.String: - contentType = "text/plain; charset=utf-8" - default: - if b, ok := body.([]byte); ok { - contentType = http.DetectContentType(b) - } else if kind == reflect.Slice { - contentType = "application/json; charset=utf-8" - } - } - - return contentType -} - -// Ripped from https://github.com/gregjones/httpcache/blob/master/httpcache.go -type cacheControl map[string]string - -func parseCacheControl(headers http.Header) cacheControl { - cc := cacheControl{} - ccHeader := headers.Get("Cache-Control") - for _, part := range strings.Split(ccHeader, ",") { - part = strings.Trim(part, " ") - if part == "" { - continue - } - if strings.ContainsRune(part, '=') { - keyval := strings.Split(part, "=") - cc[strings.Trim(keyval[0], " ")] = strings.Trim(keyval[1], ",") - } else { - cc[part] = "" - } - } - return cc -} - -// CacheExpires helper function to determine remaining time before repeating a request. -func CacheExpires(r *http.Response) time.Time { - // Figure out when the cache expires. - var expires time.Time - now, err := time.Parse(time.RFC1123, r.Header.Get("date")) - if err != nil { - return time.Now() - } - respCacheControl := parseCacheControl(r.Header) - - if maxAge, ok := respCacheControl["max-age"]; ok { - lifetime, err := time.ParseDuration(maxAge + "s") - if err != nil { - expires = now - } - expires = now.Add(lifetime) - } else { - expiresHeader := r.Header.Get("Expires") - if expiresHeader != "" { - expires, err = time.Parse(time.RFC1123, expiresHeader) - if err != nil { - expires = now - } - } - } - return expires -} - -func strlen(s string) int { - return utf8.RuneCountInString(s) -} diff --git a/samples/client/petstore-security-test/go/api_response.go b/samples/client/petstore-security-test/go/api_response.go deleted file mode 100644 index 05fd1dc4e900..000000000000 --- a/samples/client/petstore-security-test/go/api_response.go +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Swagger Petstore *_/ ' \" =end -- \\r\\n \\n \\r - * - * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ *_/ ' \" =end -- - * - * API version: 1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r - * Contact: apiteam@swagger.io *_/ ' \" =end -- \\r\\n \\n \\r - * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) - */ - -package swagger - -import ( - "net/http" -) - -type APIResponse struct { - *http.Response `json:"-"` - Message string `json:"message,omitempty"` - // Operation is the name of the swagger operation. - Operation string `json:"operation,omitempty"` - // RequestURL is the request URL. This value is always available, even if the - // embedded *http.Response is nil. - RequestURL string `json:"url,omitempty"` - // Method is the HTTP method used for the request. This value is always - // available, even if the embedded *http.Response is nil. - Method string `json:"method,omitempty"` - // Payload holds the contents of the response body (which may be nil or empty). - // This is provided here as the raw response.Body() reader will have already - // been drained. - Payload []byte `json:"-"` -} - -func NewAPIResponse(r *http.Response) *APIResponse { - - response := &APIResponse{Response: r} - return response -} - -func NewAPIResponseWithError(errorMessage string) *APIResponse { - - response := &APIResponse{Message: errorMessage} - return response -} diff --git a/samples/client/petstore-security-test/go/fake_api.go b/samples/client/petstore-security-test/go/fake_api.go deleted file mode 100644 index 13d021b9f54e..000000000000 --- a/samples/client/petstore-security-test/go/fake_api.go +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Swagger Petstore *_/ ' \" =end -- \\r\\n \\n \\r - * - * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ *_/ ' \" =end -- - * - * API version: 1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r - * Contact: apiteam@swagger.io *_/ ' \" =end -- \\r\\n \\n \\r - * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) - */ - -package swagger - -import ( - "io/ioutil" - "net/http" - "net/url" - "strings" - "golang.org/x/net/context" -) - -// Linger please -var ( - _ context.Context -) - -type FakeApiService service - -/* FakeApiService To test code injection *_/ ' \" =end -- \\r\\n \\n \\r - * @param ctx context.Context for authentication, logging, tracing, etc. -@param optional (nil or map[string]interface{}) with one or more of: - @param "testCodeInjectEndRnNR" (string) To test code injection *_/ ' \" =end -- \\r\\n \\n \\r -@return */ -func (a *FakeApiService) TestCodeInjectEndRnNR(ctx context.Context, localVarOptionals map[string]interface{}) (*http.Response, error) { - var ( - localVarHttpMethod = strings.ToUpper("Put") - localVarPostBody interface{} - localVarFileName string - localVarFileBytes []byte - ) - - // create path and map variables - localVarPath := a.client.cfg.BasePath + "/fake" - - localVarHeaderParams := make(map[string]string) - localVarQueryParams := url.Values{} - localVarFormParams := url.Values{} - if err := typeCheckParameter(localVarOptionals["testCodeInjectEndRnNR"], "string", "testCodeInjectEndRnNR"); err != nil { - return nil, err - } - - // to determine the Content-Type header - localVarHttpContentTypes := []string{"application/json", "*_/ ' =end -- "} - - // set Content-Type header - localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) - if localVarHttpContentType != "" { - localVarHeaderParams["Content-Type"] = localVarHttpContentType - } - - // to determine the Accept header - localVarHttpHeaderAccepts := []string{"application/json", "*_/ ' =end -- "} - - // set Accept header - localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) - if localVarHttpHeaderAccept != "" { - localVarHeaderParams["Accept"] = localVarHttpHeaderAccept - } - if localVarTempParam, localVarOk := localVarOptionals["testCodeInjectEndRnNR"].(string); localVarOk { - localVarFormParams.Add("test code inject */ ' " =end -- \r\n \n \r", parameterToString(localVarTempParam, "")) - } - r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) - if err != nil { - return nil, err - } - - localVarHttpResponse, err := a.client.callAPI(r) - if err != nil || localVarHttpResponse == nil { - return localVarHttpResponse, err - } - defer localVarHttpResponse.Body.Close() - if localVarHttpResponse.StatusCode >= 300 { - bodyBytes, _ := ioutil.ReadAll(localVarHttpResponse.Body) - return localVarHttpResponse, reportError("Status: %v, Body: %s", localVarHttpResponse.Status, bodyBytes) - } - return localVarHttpResponse, err -} diff --git a/samples/client/petstore/go/go-petstore-withXml/README.md b/samples/client/petstore/go/go-petstore-withXml/README.md index 4bca622853b5..b063933c1d5d 100644 --- a/samples/client/petstore/go/go-petstore-withXml/README.md +++ b/samples/client/petstore/go/go-petstore-withXml/README.md @@ -31,6 +31,7 @@ All URIs are relative to *http://petstore.swagger.io:80/v2* Class | Method | HTTP request | Description ------------ | ------------- | ------------- | ------------- *AnotherFakeApi* | [**Call123TestSpecialTags**](docs/AnotherFakeApi.md#call123testspecialtags) | **Patch** /another-fake/dummy | To test special tags +*FakeApi* | [**CreateXmlItem**](docs/FakeApi.md#createxmlitem) | **Post** /fake/create_xml_item | creates an XmlItem *FakeApi* | [**FakeOuterBooleanSerialize**](docs/FakeApi.md#fakeouterbooleanserialize) | **Post** /fake/outer/boolean | *FakeApi* | [**FakeOuterCompositeSerialize**](docs/FakeApi.md#fakeoutercompositeserialize) | **Post** /fake/outer/composite | *FakeApi* | [**FakeOuterNumberSerialize**](docs/FakeApi.md#fakeouternumberserialize) | **Post** /fake/outer/number | @@ -105,6 +106,7 @@ Class | Method | HTTP request | Description - [TypeHolderDefault](docs/TypeHolderDefault.md) - [TypeHolderExample](docs/TypeHolderExample.md) - [User](docs/User.md) + - [XmlItem](docs/XmlItem.md) ## Documentation For Authorization diff --git a/samples/client/petstore/go/go-petstore-withXml/api/openapi.yaml b/samples/client/petstore/go/go-petstore-withXml/api/openapi.yaml index 671c549a19a5..2b13b056b955 100644 --- a/samples/client/petstore/go/go-petstore-withXml/api/openapi.yaml +++ b/samples/client/petstore/go/go-petstore-withXml/api/openapi.yaml @@ -1014,6 +1014,40 @@ paths: tags: - fake x-codegen-request-body-name: body + /fake/create_xml_item: + post: + description: this route creates an XmlItem + operationId: createXmlItem + requestBody: + content: + application/xml: + schema: + $ref: '#/components/schemas/XmlItem' + application/xml; charset=utf-8: + schema: + $ref: '#/components/schemas/XmlItem' + application/xml; charset=utf-16: + schema: + $ref: '#/components/schemas/XmlItem' + text/xml: + schema: + $ref: '#/components/schemas/XmlItem' + text/xml; charset=utf-8: + schema: + $ref: '#/components/schemas/XmlItem' + text/xml; charset=utf-16: + schema: + $ref: '#/components/schemas/XmlItem' + description: XmlItem Body + required: true + responses: + 200: + content: {} + description: successful operation + summary: creates an XmlItem + tags: + - fake + x-codegen-request-body-name: XmlItem /another-fake/dummy: patch: description: To test special tags and operation ID starting with number @@ -1388,6 +1422,7 @@ components: format: date-time type: string uuid: + example: 72f98069-206d-4f12-9f12-3d1e525a8e84 format: uuid type: string password: @@ -1600,7 +1635,7 @@ components: OuterComposite: example: my_string: my_string - my_number: 0.80082819046101150206595775671303272247314453125 + my_number: 0.8008281904610115 my_boolean: true properties: my_number: @@ -1699,6 +1734,185 @@ components: - number_item - string_item type: object + XmlItem: + properties: + attribute_string: + example: string + type: string + xml: + attribute: true + attribute_number: + example: 1.234 + type: number + xml: + attribute: true + attribute_integer: + example: -2 + type: integer + xml: + attribute: true + attribute_boolean: + example: true + type: boolean + xml: + attribute: true + wrapped_array: + items: + type: integer + type: array + xml: + wrapped: true + name_string: + example: string + type: string + xml: + name: xml_name_string + name_number: + example: 1.234 + type: number + xml: + name: xml_name_number + name_integer: + example: -2 + type: integer + xml: + name: xml_name_integer + name_boolean: + example: true + type: boolean + xml: + name: xml_name_boolean + name_array: + items: + type: integer + xml: + name: xml_name_array_item + type: array + name_wrapped_array: + items: + type: integer + xml: + name: xml_name_wrapped_array_item + type: array + xml: + name: xml_name_wrapped_array + wrapped: true + prefix_string: + example: string + type: string + xml: + prefix: ab + prefix_number: + example: 1.234 + type: number + xml: + prefix: cd + prefix_integer: + example: -2 + type: integer + xml: + prefix: ef + prefix_boolean: + example: true + type: boolean + xml: + prefix: gh + prefix_array: + items: + type: integer + xml: + prefix: ij + type: array + prefix_wrapped_array: + items: + type: integer + xml: + prefix: mn + type: array + xml: + prefix: kl + wrapped: true + namespace_string: + example: string + type: string + xml: + namespace: http://a.com/schema + namespace_number: + example: 1.234 + type: number + xml: + namespace: http://b.com/schema + namespace_integer: + example: -2 + type: integer + xml: + namespace: http://c.com/schema + namespace_boolean: + example: true + type: boolean + xml: + namespace: http://d.com/schema + namespace_array: + items: + type: integer + xml: + namespace: http://e.com/schema + type: array + namespace_wrapped_array: + items: + type: integer + xml: + namespace: http://g.com/schema + type: array + xml: + namespace: http://f.com/schema + wrapped: true + prefix_ns_string: + example: string + type: string + xml: + namespace: http://a.com/schema + prefix: a + prefix_ns_number: + example: 1.234 + type: number + xml: + namespace: http://b.com/schema + prefix: b + prefix_ns_integer: + example: -2 + type: integer + xml: + namespace: http://c.com/schema + prefix: c + prefix_ns_boolean: + example: true + type: boolean + xml: + namespace: http://d.com/schema + prefix: d + prefix_ns_array: + items: + type: integer + xml: + namespace: http://e.com/schema + prefix: e + type: array + prefix_ns_wrapped_array: + items: + type: integer + xml: + namespace: http://g.com/schema + prefix: g + type: array + xml: + namespace: http://f.com/schema + prefix: f + wrapped: true + type: object + xml: + namespace: http://a.com/schema + prefix: pre securitySchemes: petstore_auth: flows: diff --git a/samples/client/petstore/go/go-petstore-withXml/api_fake.go b/samples/client/petstore/go/go-petstore-withXml/api_fake.go index 9d4f189f9551..dcc48da69379 100644 --- a/samples/client/petstore/go/go-petstore-withXml/api_fake.go +++ b/samples/client/petstore/go/go-petstore-withXml/api_fake.go @@ -27,6 +27,74 @@ var ( type FakeApiService service +/* +FakeApiService creates an XmlItem +this route creates an XmlItem + * @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + * @param xmlItem XmlItem Body +*/ +func (a *FakeApiService) CreateXmlItem(ctx context.Context, xmlItem XmlItem) (*http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Post") + localVarPostBody interface{} + localVarFormFileName string + localVarFileName string + localVarFileBytes []byte + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/fake/create_xml_item" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/xml", "application/xml; charset=utf-8", "application/xml; charset=utf-16", "text/xml", "text/xml; charset=utf-8", "text/xml; charset=utf-16"} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{} + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + // body params + localVarPostBody = &xmlItem + r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFormFileName, localVarFileName, localVarFileBytes) + if err != nil { + return nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return localVarHttpResponse, err + } + + localVarBody, err := ioutil.ReadAll(localVarHttpResponse.Body) + localVarHttpResponse.Body.Close() + if err != nil { + return localVarHttpResponse, err + } + + if localVarHttpResponse.StatusCode >= 300 { + newErr := GenericOpenAPIError{ + body: localVarBody, + error: localVarHttpResponse.Status, + } + return localVarHttpResponse, newErr + } + + return localVarHttpResponse, nil +} + /* FakeApiService Test serialization of outer boolean types diff --git a/samples/client/petstore/go/go-petstore-withXml/api_fake_classname_tags123.go b/samples/client/petstore/go/go-petstore-withXml/api_fake_classname_tags123.go index 91fc17598ad1..82217020bb27 100644 --- a/samples/client/petstore/go/go-petstore-withXml/api_fake_classname_tags123.go +++ b/samples/client/petstore/go/go-petstore-withXml/api_fake_classname_tags123.go @@ -80,7 +80,6 @@ func (a *FakeClassnameTags123ApiService) TestClassname(ctx context.Context, body localVarQueryParams.Add("api_key_query", key) } } - r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFormFileName, localVarFileName, localVarFileBytes) if err != nil { return localVarReturnValue, nil, err diff --git a/samples/client/petstore/go/go-petstore-withXml/api_pet.go b/samples/client/petstore/go/go-petstore-withXml/api_pet.go index b39971e84fa9..7f09af3a7b16 100644 --- a/samples/client/petstore/go/go-petstore-withXml/api_pet.go +++ b/samples/client/petstore/go/go-petstore-withXml/api_pet.go @@ -401,7 +401,6 @@ func (a *PetApiService) GetPetById(ctx context.Context, petId int64) (Pet, *http localVarHeaderParams["api_key"] = key } } - r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFormFileName, localVarFileName, localVarFileBytes) if err != nil { return localVarReturnValue, nil, err diff --git a/samples/client/petstore/go/go-petstore-withXml/api_store.go b/samples/client/petstore/go/go-petstore-withXml/api_store.go index fe181797a812..50ca891a2574 100644 --- a/samples/client/petstore/go/go-petstore-withXml/api_store.go +++ b/samples/client/petstore/go/go-petstore-withXml/api_store.go @@ -145,7 +145,6 @@ func (a *StoreApiService) GetInventory(ctx context.Context) (map[string]int32, * localVarHeaderParams["api_key"] = key } } - r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFormFileName, localVarFileName, localVarFileBytes) if err != nil { return localVarReturnValue, nil, err diff --git a/samples/client/petstore/go/go-petstore-withXml/client.go b/samples/client/petstore/go/go-petstore-withXml/client.go index 7e4ec1871a0b..87152ec107b5 100644 --- a/samples/client/petstore/go/go-petstore-withXml/client.go +++ b/samples/client/petstore/go/go-petstore-withXml/client.go @@ -34,8 +34,8 @@ import ( ) var ( - jsonCheck = regexp.MustCompile("(?i:[application|text]/json)") - xmlCheck = regexp.MustCompile("(?i:[application|text]/xml)") + jsonCheck = regexp.MustCompile(`(?i:(?:application|text)/(?:vnd\.[^;]+\+)?json)`) + xmlCheck = regexp.MustCompile(`(?i:(?:application|text)/xml)`) ) // APIClient manages communication with the OpenAPI Petstore API v1.0.0 @@ -329,17 +329,18 @@ func (c *APIClient) prepareRequest( } func (c *APIClient) decode(v interface{}, b []byte, contentType string) (err error) { - if strings.Contains(contentType, "application/xml") { - if err = xml.Unmarshal(b, v); err != nil { - return err - } - return nil - } else if strings.Contains(contentType, "application/json") { - if err = json.Unmarshal(b, v); err != nil { - return err - } - return nil + if xmlCheck.MatchString(contentType) { + if err = xml.Unmarshal(b, v); err != nil { + return err } + return nil + } + if jsonCheck.MatchString(contentType) { + if err = json.Unmarshal(b, v); err != nil { + return err + } + return nil + } return errors.New("undefined response type") } diff --git a/samples/client/petstore/go/go-petstore-withXml/docs/FakeApi.md b/samples/client/petstore/go/go-petstore-withXml/docs/FakeApi.md index d474551a034e..e6d0dec3fe1f 100644 --- a/samples/client/petstore/go/go-petstore-withXml/docs/FakeApi.md +++ b/samples/client/petstore/go/go-petstore-withXml/docs/FakeApi.md @@ -4,6 +4,7 @@ All URIs are relative to *http://petstore.swagger.io:80/v2* Method | HTTP request | Description ------------- | ------------- | ------------- +[**CreateXmlItem**](FakeApi.md#CreateXmlItem) | **Post** /fake/create_xml_item | creates an XmlItem [**FakeOuterBooleanSerialize**](FakeApi.md#FakeOuterBooleanSerialize) | **Post** /fake/outer/boolean | [**FakeOuterCompositeSerialize**](FakeApi.md#FakeOuterCompositeSerialize) | **Post** /fake/outer/composite | [**FakeOuterNumberSerialize**](FakeApi.md#FakeOuterNumberSerialize) | **Post** /fake/outer/number | @@ -18,6 +19,34 @@ Method | HTTP request | Description [**TestJsonFormData**](FakeApi.md#TestJsonFormData) | **Get** /fake/jsonFormData | test json serialization of form data +# **CreateXmlItem** +> CreateXmlItem(ctx, xmlItem) +creates an XmlItem + +this route creates an XmlItem + +### Required Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **ctx** | **context.Context** | context for authentication, logging, cancellation, deadlines, tracing, etc. + **xmlItem** | [**XmlItem**](XmlItem.md)| XmlItem Body | + +### Return type + + (empty response body) + +### Authorization + +No authorization required + +### HTTP request headers + + - **Content-Type**: application/xml, application/xml; charset=utf-8, application/xml; charset=utf-16, text/xml, text/xml; charset=utf-8, text/xml; charset=utf-16 + - **Accept**: Not defined + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + # **FakeOuterBooleanSerialize** > bool FakeOuterBooleanSerialize(ctx, optional) diff --git a/samples/client/petstore/go/go-petstore-withXml/docs/TypeHolderDefault.md b/samples/client/petstore/go/go-petstore-withXml/docs/TypeHolderDefault.md new file mode 100644 index 000000000000..080c12a02f43 --- /dev/null +++ b/samples/client/petstore/go/go-petstore-withXml/docs/TypeHolderDefault.md @@ -0,0 +1,14 @@ +# TypeHolderDefault + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**StringItem** | **string** | | [default to what] +**NumberItem** | **float32** | | +**IntegerItem** | **int32** | | +**BoolItem** | **bool** | | [default to true] +**ArrayItem** | **[]int32** | | + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/client/petstore-security-test/go/docs/ModelReturn.md b/samples/client/petstore/go/go-petstore-withXml/docs/TypeHolderExample.md similarity index 59% rename from samples/client/petstore-security-test/go/docs/ModelReturn.md rename to samples/client/petstore/go/go-petstore-withXml/docs/TypeHolderExample.md index 594e207dc3fe..231c2a18722f 100644 --- a/samples/client/petstore-security-test/go/docs/ModelReturn.md +++ b/samples/client/petstore/go/go-petstore-withXml/docs/TypeHolderExample.md @@ -1,9 +1,13 @@ -# ModelReturn +# TypeHolderExample ## Properties Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- -**Return_** | **int32** | property description *_/ ' \" =end -- \\r\\n \\n \\r | [optional] [default to null] +**StringItem** | **string** | | +**NumberItem** | **float32** | | +**IntegerItem** | **int32** | | +**BoolItem** | **bool** | | +**ArrayItem** | **[]int32** | | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/petstore/go/go-petstore-withXml/docs/XmlItem.md b/samples/client/petstore/go/go-petstore-withXml/docs/XmlItem.md new file mode 100644 index 000000000000..573fac8e2d5c --- /dev/null +++ b/samples/client/petstore/go/go-petstore-withXml/docs/XmlItem.md @@ -0,0 +1,38 @@ +# XmlItem + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**AttributeString** | **string** | | [optional] +**AttributeNumber** | **float32** | | [optional] +**AttributeInteger** | **int32** | | [optional] +**AttributeBoolean** | **bool** | | [optional] +**WrappedArray** | **[]int32** | | [optional] +**NameString** | **string** | | [optional] +**NameNumber** | **float32** | | [optional] +**NameInteger** | **int32** | | [optional] +**NameBoolean** | **bool** | | [optional] +**NameArray** | **[]int32** | | [optional] +**NameWrappedArray** | **[]int32** | | [optional] +**PrefixString** | **string** | | [optional] +**PrefixNumber** | **float32** | | [optional] +**PrefixInteger** | **int32** | | [optional] +**PrefixBoolean** | **bool** | | [optional] +**PrefixArray** | **[]int32** | | [optional] +**PrefixWrappedArray** | **[]int32** | | [optional] +**NamespaceString** | **string** | | [optional] +**NamespaceNumber** | **float32** | | [optional] +**NamespaceInteger** | **int32** | | [optional] +**NamespaceBoolean** | **bool** | | [optional] +**NamespaceArray** | **[]int32** | | [optional] +**NamespaceWrappedArray** | **[]int32** | | [optional] +**PrefixNsString** | **string** | | [optional] +**PrefixNsNumber** | **float32** | | [optional] +**PrefixNsInteger** | **int32** | | [optional] +**PrefixNsBoolean** | **bool** | | [optional] +**PrefixNsArray** | **[]int32** | | [optional] +**PrefixNsWrappedArray** | **[]int32** | | [optional] + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/client/petstore/go/go-petstore-withXml/model_type_holder_default.go b/samples/client/petstore/go/go-petstore-withXml/model_type_holder_default.go new file mode 100644 index 000000000000..b4883cac9599 --- /dev/null +++ b/samples/client/petstore/go/go-petstore-withXml/model_type_holder_default.go @@ -0,0 +1,19 @@ +/* + * OpenAPI Petstore + * + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * API version: 1.0.0 + */ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package petstore + +type TypeHolderDefault struct { + StringItem string `json:"string_item" xml:"string_item"` + NumberItem float32 `json:"number_item" xml:"number_item"` + IntegerItem int32 `json:"integer_item" xml:"integer_item"` + BoolItem bool `json:"bool_item" xml:"bool_item"` + ArrayItem []int32 `json:"array_item" xml:"array_item"` +} diff --git a/samples/client/petstore/go/go-petstore-withXml/model_type_holder_example.go b/samples/client/petstore/go/go-petstore-withXml/model_type_holder_example.go new file mode 100644 index 000000000000..af3fac4aa6e7 --- /dev/null +++ b/samples/client/petstore/go/go-petstore-withXml/model_type_holder_example.go @@ -0,0 +1,19 @@ +/* + * OpenAPI Petstore + * + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * API version: 1.0.0 + */ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package petstore + +type TypeHolderExample struct { + StringItem string `json:"string_item" xml:"string_item"` + NumberItem float32 `json:"number_item" xml:"number_item"` + IntegerItem int32 `json:"integer_item" xml:"integer_item"` + BoolItem bool `json:"bool_item" xml:"bool_item"` + ArrayItem []int32 `json:"array_item" xml:"array_item"` +} diff --git a/samples/client/petstore/go/go-petstore-withXml/model_xml_item.go b/samples/client/petstore/go/go-petstore-withXml/model_xml_item.go new file mode 100644 index 000000000000..0276796aca62 --- /dev/null +++ b/samples/client/petstore/go/go-petstore-withXml/model_xml_item.go @@ -0,0 +1,43 @@ +/* + * OpenAPI Petstore + * + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * API version: 1.0.0 + */ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package petstore + +type XmlItem struct { + AttributeString string `json:"attribute_string,omitempty" xml:"attribute_string,attr"` + AttributeNumber float32 `json:"attribute_number,omitempty" xml:"attribute_number,attr"` + AttributeInteger int32 `json:"attribute_integer,omitempty" xml:"attribute_integer,attr"` + AttributeBoolean bool `json:"attribute_boolean,omitempty" xml:"attribute_boolean,attr"` + WrappedArray []int32 `json:"wrapped_array,omitempty" xml:"wrapped_array"` + NameString string `json:"name_string,omitempty" xml:"name_string"` + NameNumber float32 `json:"name_number,omitempty" xml:"name_number"` + NameInteger int32 `json:"name_integer,omitempty" xml:"name_integer"` + NameBoolean bool `json:"name_boolean,omitempty" xml:"name_boolean"` + NameArray []int32 `json:"name_array,omitempty" xml:"name_array"` + NameWrappedArray []int32 `json:"name_wrapped_array,omitempty" xml:"name_wrapped_array"` + PrefixString string `json:"prefix_string,omitempty" xml:"prefix_string"` + PrefixNumber float32 `json:"prefix_number,omitempty" xml:"prefix_number"` + PrefixInteger int32 `json:"prefix_integer,omitempty" xml:"prefix_integer"` + PrefixBoolean bool `json:"prefix_boolean,omitempty" xml:"prefix_boolean"` + PrefixArray []int32 `json:"prefix_array,omitempty" xml:"prefix_array"` + PrefixWrappedArray []int32 `json:"prefix_wrapped_array,omitempty" xml:"prefix_wrapped_array"` + NamespaceString string `json:"namespace_string,omitempty" xml:"namespace_string"` + NamespaceNumber float32 `json:"namespace_number,omitempty" xml:"namespace_number"` + NamespaceInteger int32 `json:"namespace_integer,omitempty" xml:"namespace_integer"` + NamespaceBoolean bool `json:"namespace_boolean,omitempty" xml:"namespace_boolean"` + NamespaceArray []int32 `json:"namespace_array,omitempty" xml:"namespace_array"` + NamespaceWrappedArray []int32 `json:"namespace_wrapped_array,omitempty" xml:"namespace_wrapped_array"` + PrefixNsString string `json:"prefix_ns_string,omitempty" xml:"prefix_ns_string"` + PrefixNsNumber float32 `json:"prefix_ns_number,omitempty" xml:"prefix_ns_number"` + PrefixNsInteger int32 `json:"prefix_ns_integer,omitempty" xml:"prefix_ns_integer"` + PrefixNsBoolean bool `json:"prefix_ns_boolean,omitempty" xml:"prefix_ns_boolean"` + PrefixNsArray []int32 `json:"prefix_ns_array,omitempty" xml:"prefix_ns_array"` + PrefixNsWrappedArray []int32 `json:"prefix_ns_wrapped_array,omitempty" xml:"prefix_ns_wrapped_array"` +} diff --git a/samples/openapi3/server/petstore/go-api-server/api/openapi.yaml b/samples/openapi3/server/petstore/go-api-server/api/openapi.yaml index bea7646c738c..2cd94b385f37 100644 --- a/samples/openapi3/server/petstore/go-api-server/api/openapi.yaml +++ b/samples/openapi3/server/petstore/go-api-server/api/openapi.yaml @@ -81,6 +81,9 @@ paths: summary: Update an existing pet tags: - pet + servers: + - url: http://petstore.swagger.io/v2 + - url: http://path-server-test.petstore.local/v2 /pet/findByStatus: get: description: Multiple status values can be provided with comma separated strings @@ -1462,6 +1465,7 @@ components: format: date-time type: string uuid: + example: 72f98069-206d-4f12-9f12-3d1e525a8e84 format: uuid type: string password: @@ -1518,6 +1522,12 @@ components: type: number outerEnum: $ref: '#/components/schemas/OuterEnum' + outerEnumInteger: + $ref: '#/components/schemas/OuterEnumInteger' + outerEnumDefaultValue: + $ref: '#/components/schemas/OuterEnumDefaultValue' + outerEnumIntegerDefaultValue: + $ref: '#/components/schemas/OuterEnumIntegerDefaultValue' required: - enum_string_required type: object @@ -1678,10 +1688,32 @@ components: - approved - delivered type: string + OuterEnumInteger: + enum: + - 0 + - 1 + - 2 + format: int32 + type: integer + OuterEnumDefaultValue: + default: placed + enum: + - placed + - approved + - delivered + type: string + OuterEnumIntegerDefaultValue: + default: 0 + enum: + - 0 + - 1 + - 2 + format: int32 + type: integer OuterComposite: example: my_string: my_string - my_number: 0.80082819046101150206595775671303272247314453125 + my_number: 0.8008281904610115 my_boolean: true properties: my_number: diff --git a/samples/openapi3/server/petstore/go-api-server/go/model_enum_test_.go b/samples/openapi3/server/petstore/go-api-server/go/model_enum_test_.go index ce8e479d7b96..01b52e667f4f 100644 --- a/samples/openapi3/server/petstore/go-api-server/go/model_enum_test_.go +++ b/samples/openapi3/server/petstore/go-api-server/go/model_enum_test_.go @@ -20,4 +20,10 @@ type EnumTest struct { EnumNumber float64 `json:"enum_number,omitempty"` OuterEnum OuterEnum `json:"outerEnum,omitempty"` + + OuterEnumInteger OuterEnumInteger `json:"outerEnumInteger,omitempty"` + + OuterEnumDefaultValue OuterEnumDefaultValue `json:"outerEnumDefaultValue,omitempty"` + + OuterEnumIntegerDefaultValue OuterEnumIntegerDefaultValue `json:"outerEnumIntegerDefaultValue,omitempty"` } diff --git a/samples/openapi3/server/petstore/go-api-server/go/model_outer_enum_default_value.go b/samples/openapi3/server/petstore/go-api-server/go/model_outer_enum_default_value.go new file mode 100644 index 000000000000..12881121ff32 --- /dev/null +++ b/samples/openapi3/server/petstore/go-api-server/go/model_outer_enum_default_value.go @@ -0,0 +1,19 @@ +/* + * OpenAPI Petstore + * + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * API version: 1.0.0 + * Generated by: OpenAPI Generator (https://openapi-generator.tech) + */ + +package petstoreserver + +type OuterEnumDefaultValue string + +// List of OuterEnumDefaultValue +const ( + PLACED OuterEnumDefaultValue = "placed" + APPROVED OuterEnumDefaultValue = "approved" + DELIVERED OuterEnumDefaultValue = "delivered" +) diff --git a/samples/openapi3/server/petstore/go-api-server/go/model_outer_enum_integer.go b/samples/openapi3/server/petstore/go-api-server/go/model_outer_enum_integer.go new file mode 100644 index 000000000000..de3969668436 --- /dev/null +++ b/samples/openapi3/server/petstore/go-api-server/go/model_outer_enum_integer.go @@ -0,0 +1,19 @@ +/* + * OpenAPI Petstore + * + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * API version: 1.0.0 + * Generated by: OpenAPI Generator (https://openapi-generator.tech) + */ + +package petstoreserver + +type OuterEnumInteger int32 + +// List of OuterEnumInteger +const ( + _0 OuterEnumInteger = "0" + _1 OuterEnumInteger = "1" + _2 OuterEnumInteger = "2" +) diff --git a/samples/openapi3/server/petstore/go-api-server/go/model_outer_enum_integer_default_value.go b/samples/openapi3/server/petstore/go-api-server/go/model_outer_enum_integer_default_value.go new file mode 100644 index 000000000000..2e4dc213ea24 --- /dev/null +++ b/samples/openapi3/server/petstore/go-api-server/go/model_outer_enum_integer_default_value.go @@ -0,0 +1,19 @@ +/* + * OpenAPI Petstore + * + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * API version: 1.0.0 + * Generated by: OpenAPI Generator (https://openapi-generator.tech) + */ + +package petstoreserver + +type OuterEnumIntegerDefaultValue int32 + +// List of OuterEnumIntegerDefaultValue +const ( + _0 OuterEnumIntegerDefaultValue = "0" + _1 OuterEnumIntegerDefaultValue = "1" + _2 OuterEnumIntegerDefaultValue = "2" +) diff --git a/samples/server/petstore/go-api-server/go/README.md b/samples/server/petstore/go-api-server/go/README.md index 30088c34683d..fbcf4ae661b0 100644 --- a/samples/server/petstore/go-api-server/go/README.md +++ b/samples/server/petstore/go-api-server/go/README.md @@ -10,7 +10,7 @@ By using the [OpenAPI-Spec](https://github.com/OAI/OpenAPI-Specification) from a To see how to make this your own, look here: -[README]((https://openapi-generator.tech)) +[README](https://openapi-generator.tech) - API version: 1.0.0 diff --git a/samples/server/petstore/go-gin-api-server/go/README.md b/samples/server/petstore/go-gin-api-server/go/README.md index d29353f16c7c..e88bc984b8c5 100644 --- a/samples/server/petstore/go-gin-api-server/go/README.md +++ b/samples/server/petstore/go-gin-api-server/go/README.md @@ -14,8 +14,8 @@ To see how to make this your own, look here: - API version: 1.0.0 - ### Running the server + To run the server, follow these simple steps: ``` @@ -27,58 +27,14 @@ To run the server in a docker container docker build --network=host -t petstoreserver . ``` -Once image is built use +Once the image is built, just run ``` docker run --rm -it petstoreserver ``` ### Known Issue -The endpoint `/v2/pet/findByTags` and `/v2/pet/:petId` are conflict with gin. -This is a known issue of gin. Please refer [gin-gonic/gin#388](https://github.com/gin-gonic/gin/issues/388) +Endpoints sharing a common path may result in issues. For example, `/v2/pet/findByTags` and `/v2/pet/:petId` will result in an issue with the Gin framework. For more information about this known limitation, please refer to [gin-gonic/gin#388](https://github.com/gin-gonic/gin/issues/388) for more information. -You can manually fix it by updating the path and handler. Please refer [gin-gonic/gin/issues/205#issuecomment-296155497](https://github.com/gin-gonic/gin/issues/205#issuecomment-296155497) and an example below. +A workaround is to manually update the path and handler. Please refer to [gin-gonic/gin/issues/205#issuecomment-296155497](https://github.com/gin-gonic/gin/issues/205#issuecomment-296155497) for more information. - -`routers.go` - -```diff -var routes = Routes{ - { - "Index", - "GET", - "/v2/", - Index, - }, - -- { -- "FindPetsByTags", -- strings.ToUpper("Get"), -- "/v2/pet/findByTags", -- FindPetsByTags, -- }, - - { - "GetPetById", - strings.ToUpper("Get"), - "/v2/pet/:petId", - GetPetById, - }, -} -``` - -`api_pet.go` - -```diff -// GetPetById - Find pet by ID -func GetPetById(c *gin.Context) { -- c.JSON(http.StatusOK, gin.H{}) -+ petId := c.Param("petId") -+ -+ if petId == "findByTags" { -+ FindPetsByTags(c) -+ } else { -+ c.JSON(http.StatusOK, gin.H{}) -+ } -} -``` \ No newline at end of file