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

BUG Null-typed extensions elements disappear when creating yaml #4708

Open
anton-okolelov opened this issue Jul 2, 2024 · 0 comments
Open

Comments

@anton-okolelov
Copy link

When save openapi to yaml ( ObjectMapperFactory.createYaml(true).writeValueAsString(openApi) )

  1. some fields (with null type) in extensions disappear
  2. in licence section "extensions" word appear, but it shouldn't be there

As far I understand, parsing works correctly with extensions, but creating yaml works with bugs

Full code to reproduce:

import io.swagger.parser.OpenAPIParser;
import io.swagger.v3.core.util.ObjectMapperFactory;

public class Main  {
    public static void main(String[] args) {
        System.out.println("Hello World!");
        OpenAPIParser parser = new OpenAPIParser();
        var result = parser.readContents("""
openapi: 3.1.0
info:
  title: Sample Pet Store App
  contact:
    name: API Support
    url: https://www.example.com/support
    email: [email protected]
    x-myext:
      key1: 1
      key2: null
  license:
    name: asassaas
    x-licence:
      key1: 1
      key2: null
  version: 1.0.1
  summary: A pet store manager.
  x-info:
    key1: 1
    key2: null
    """, null, null);

        var openApi = result.getOpenAPI();

        // now save it as yaml
        var isV31 = true;
        try {
            var yaml = ObjectMapperFactory.createYaml(true).writeValueAsString(openApi);
            System.out.println(yaml);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}

output is:

openapi: 3.1.0
info:
  title: Sample Pet Store App
  contact:
    name: API Support
    url: https://www.example.com/support
    email: [email protected]
    x-myext:
      key1: 1
  license:
    name: asassaas
    extensions:
      x-licence:
        key1: 1
  version: 1.0.1
  summary: A pet store manager.
  x-info:
    key1: 1
servers:
- url: /

dependencies:

  <dependencies>
    <dependency>
      <groupId>io.swagger.parser.v3</groupId>
      <artifactId>swagger-parser</artifactId>
      <version>2.1.22</version>
    </dependency>

  </dependencies>
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