Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spec parser ignores response entries when there's an extension #165

Closed
zmay2030 opened this issue Apr 19, 2023 · 0 comments
Closed

Spec parser ignores response entries when there's an extension #165

zmay2030 opened this issue Apr 19, 2023 · 0 comments

Comments

@zmay2030
Copy link

Problem statement

According to the OpenAPI Spec, OpenAPI Extensions are allowed to be under responses. But when loading the spec via load.Spec(), the response codes are completely ignored if there is an extension. If there is no extension, then the response codes are parsed and hydrated just fine.

OpenAPI specification

OpenAPI Extensions

Steps to reproduce

Spec file (spec.json)

{
  "swagger": "2.0",
  "info": {
    "title": "Swagger Fixture",
    "version": "1.0",
    "x-ext-info-1": "a",
    "x-ext-info-2": "b"
  },
  "paths": {
    "/b/": {
      "get": {
        "responses": {
          "200": {
            "description": "200 response"
          },
          "x-ext-resp": "response ext"
        }
      }
    }
  }
}

Code:

package main

import (
	"github.com/davecgh/go-spew/spew"
	"github.com/go-openapi/loads"
)

func main() {
	storedSpec, err := loads.Spec("./spec.json")
	if err != nil {
		panic(err)
	}

	spew.Dump(storedSpec.Spec().Paths.Paths["/b/"].Get.Responses)
}

Output:

aven30@COMP archive % go run main.go
(*spec.Responses)(0x140001a4df8)({
 VendorExtensible: (spec.VendorExtensible) {
  Extensions: (spec.Extensions) (len=1) {
   (string) (len=10) "x-ext-resp": (string) (len=12) "response ext"
  }
 },
 ResponsesProps: (spec.ResponsesProps) {
  Default: (*spec.Response)(<nil>),
  StatusCodeResponses: (map[int]spec.Response) <nil>
 }
})

But when you remove the "x-ext-resp": "response ext", it ends up dumping the following:

aven30@COMP archive % go run main.go
(*spec.Responses)(0x140000a2df8)({
 VendorExtensible: (spec.VendorExtensible) {
  Extensions: (spec.Extensions) <nil>
 },
 ResponsesProps: (spec.ResponsesProps) {
  Default: (*spec.Response)(<nil>),
  StatusCodeResponses: (map[int]spec.Response) (len=1) {
   (int) 200: (spec.Response) {
    Refable: (spec.Refable) {
     Ref: (spec.Ref) 
    },
    ResponseProps: (spec.ResponseProps) {
     Description: (string) (len=12) "200 response",
     Schema: (*spec.Schema)(<nil>),
     Headers: (map[string]spec.Header) <nil>,
     Examples: (map[string]interface {}) <nil>
    },
    VendorExtensible: (spec.VendorExtensible) {
     Extensions: (spec.Extensions) <nil>
    }
   }
  }
 }
})

Environment

swagger version:latest dev
go version: 1.19.1
OS: Mac

zmay2030 pushed a commit to zmay2030/spec that referenced this issue Apr 19, 2023
zmay2030 pushed a commit to zmay2030/spec that referenced this issue Apr 19, 2023
Signed-off-by: Ahmad Moudani <ahmad.moudani@crowdstrike.com>
zmay2030 pushed a commit to zmay2030/spec that referenced this issue Apr 19, 2023
Signed-off-by: Aven <aven30@gmail.com>
zmay2030 pushed a commit to zmay2030/spec that referenced this issue Apr 19, 2023
Signed-off-by: Ahmad <aven30@gmail.com>
zmay2030 pushed a commit to zmay2030/spec that referenced this issue Apr 20, 2023
Signed-off-by: Ahmad Ma <aven30@gmail.com>
casualjim added a commit that referenced this issue Apr 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant