pb33f / libopenapi

libopenapi is a fully featured, high performance OpenAPI 3.1, 3.0 and Swagger parser, library, validator and toolkit for golang applications.
https://pb33f.io/libopenapi/
Other
482 stars 64 forks source link

Support extensions for `info.contact` object in OpenAPI 3.1.0 #330

Closed dani2819 closed 1 month ago

dani2819 commented 2 months ago

Current Behavior

When parsing an OpenAPI 3.1.0 document with extensions in the info.contact object, the library removes the extensions under info.contact. This results in loss of custom metadata that is intended to be retained for various use cases.

Expected Behavior

According to the OpenAPI 3.1.0 specification, it is valid to use extensions (properties starting with x-) within the info.contact object. The library should correctly parse and retain these extensions.

Example of a valid OpenAPI 3.1 document:

openapi: 3.1.0
info:
  title: Sample API
  version: 1.0.0
  contact:
    name: API Support
    x-custom-extension: "Custom Extension Value"
paths: {}

Steps to Reproduce

  1. Create an OpenAPI 3.1.0 document that includes extensions within the info.contact object.
  2. Use the library to parse the OpenAPI document.
  3. Observe that the extensions are missing in the parsed output.

Example Code

package main

import (
    "github.com/pb33f/libopenapi"
    "os"
)

func main() {
    oasFile, _ := os.ReadFile("sample.yaml")
    document, _ := libopenapi.NewDocument(oasFile)
    document.BuildV3Model()
    b, _ := document.Render()
    _ = os.WriteFile("output.yaml", b, 0644)
}

The output.yaml does not contain x- properties under info.contact

Environment

daveshanley commented 1 month ago

This was fixed here: https://github.com/pb33f/libopenapi/commit/0200809765f7018b6fe4ee14cf6d148e77761f6e

This issue cannot be re-created anymore with libopenapi v0.18.1+