Giter Club home page Giter Club logo

Comments (8)

daveshanley avatar daveshanley commented on September 18, 2024 1

Oh, I see, yeah, that should not happen. Will circle back to this on the next bug run at the end of the month.

from libopenapi.

TristanSpeakEasy avatar TristanSpeakEasy commented on September 18, 2024

Have just run into this myself

from libopenapi.

daveshanley avatar daveshanley commented on September 18, 2024

No problem, a simple fix in a couple of places. I'll work on this shortly.

from libopenapi.

daveshanley avatar daveshanley commented on September 18, 2024

Available in v0.3.1

from libopenapi.

JoeReid avatar JoeReid commented on September 18, 2024

@daveshanley There seems to be a regression of this issue in the v0.7.0 release.
However, I have not checked previous versions to see if this issue regressed prior to the latest release.

I have also not checked if #54 has also re-surfaced, but I assume it is likely.

Happy to help with a fix, if this would be useful. I would need some guidance with the codebase though.

from libopenapi.

daveshanley avatar daveshanley commented on September 18, 2024

@daveshanley There seems to be a regression of this issue in the v0.7.0 release. However, I have not checked previous versions to see if this issue regressed prior to the latest release.

I have also not checked if #54 has also re-surfaced, but I assume it is likely.

Happy to help with a fix, if this would be useful. I would need some guidance with the codebase though.

Hi Joe,

Generally with each bug fix, I add a test to validate and prevent regressions. I may have missed this one, but I haven't heard any other comments from folks about it regressing.

I do remember seeing that code again on my travels recently, but I didn't touch it, at least I can't remember touching it. So what would be helpful is a reproducible sample?

from libopenapi.

JoeReid avatar JoeReid commented on September 18, 2024

@daveshanley There seems to be a regression of this issue in the v0.7.0 release. However, I have not checked previous versions to see if this issue regressed prior to the latest release.
I have also not checked if #54 has also re-surfaced, but I assume it is likely.
Happy to help with a fix, if this would be useful. I would need some guidance with the codebase though.

Hi Joe,

Generally with each bug fix, I add a test to validate and prevent regressions. I may have missed this one, but I haven't heard any other comments from folks about it regressing.

I do remember seeing that code again on my travels recently, but I didn't touch it, at least I can't remember touching it. So what would be helpful is a reproducible sample?

Thanks for your swift response 👍

Under further investigation, the issue seems to only apply to response headers, and request headers are working as expected.
In which case this may be an issue that has not be reported before.

The following is a main.go file that parses two minimal openapi files, one with x- prefixed headers, one without.
(I would've provided a playground link, but alas, the library doesn't pull before the execution timeout)

package main

import (
	"fmt"

	"github.com/pb33f/libopenapi"
)

func main() {
	fmt.Println("Spec with x-:")
	printHeaders(`openapi: 3.0.0
paths:
  /pets:
    get:
      parameters:
        - name: x-api-key
          in: header
      responses:
        '200':
          headers:
            x-next:
              schema:
                type: string
          content:
            application/json:
              schema:
                type: object
`)

	fmt.Println("Spec without x-:")
	printHeaders(`openapi: 3.0.0
paths:
  /pets:
    get:
      parameters:
        - name: api-key
          in: header
      responses:
        '200':
          headers:
            next:
              schema:
                type: string
          content:
            application/json:
              schema:
                type: object
`)
}

func printHeaders(spec string) {
	document, err := libopenapi.NewDocument([]byte(spec))
	if err != nil {
		panic(err)
	}

	v3Model, errs := document.BuildV3Model()
	if len(errs) > 0 {
		panic(errs)
	}

	for _, pathItem := range v3Model.Model.Paths.PathItems {
		for _, op := range pathItem.GetOperations() {
			fmt.Printf("\tRequest headers:\n")

			for _, param := range op.Parameters {
				if param.In == "header" {
					fmt.Printf("\t\t- %s\n", param.Name)
				}
			}

			fmt.Printf("\tResponse headers:\n")
			for _, resp := range op.Responses.Codes {
				for headerName, _ := range resp.Headers {
					fmt.Printf("\t\t- %s\n", headerName)
				}
			}
		}
	}
}

As can be seen in the output of this file's execution, request headers where correctly found, but the response headers were
only provided when not prefixed.

$ go run main.go
Spec with x-:
        Request headers:
                - x-api-key
        Response headers:
Spec without x-:
        Request headers:
                - api-key
        Response headers:
                - next

Thanks for your time on this.

from libopenapi.

daveshanley avatar daveshanley commented on September 18, 2024

@JoeReid Can you try v0.8.3

Header keys in responses can now use extension prefixes.

from libopenapi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.