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

implements exampleSetFlag to flag deserialization of null example vs missing #3637

Merged
merged 1 commit into from Jul 16, 2020

Conversation

frantuma
Copy link
Member

No description provided.

@cvgaviao
Copy link

@frantuma, I think I'm getting a collateral effect of this change in the Parser. When serializing the OpenAPI object, the exampleSetFlag is being written in my YAML file.

  parameters:
    ParamP-App-id:
      name: app-id
      in: path
      required: true
      style: simple
      explode: false
      schema:
        type: integer
        format: int32
        exampleSetFlag: false

@frantuma
Copy link
Member Author

@cvgaviao

it's possible that you're not using swagger-core Json or Yaml objects; these guys basically wrap a customized ObjectMapper, among the other things registering SchemaMixin which is excluding exampleSetFlag from serialization.

You would use them e.g by calling Yaml.pretty(openAPI).

@cvgaviao
Copy link

@cvgaviao

it's possible that you're not using swagger-core Json or Yaml objects; these guys basically wrap a customized ObjectMapper, among the other things registering SchemaMixin which is excluding exampleSetFlag from serialization.

You would use them e.g by calling Yaml.pretty(openAPI).

@frantuma, well I'm using exactly this with openapi-generator and swagger-parser 2.0.20:

      String openapiYaml = Yaml.pretty(openAPI);
      Files.write(outputFile.resolve(outputFile),
                  openapiYaml.getBytes(StandardCharsets.UTF_8));

And it being working well, but after moving to the 2.0.22-SNAPSHOT the problem appears.

@frantuma
Copy link
Member Author

@cvgaviao I am not able to reproduce this, it successfully tests in core and latest parser.

Possibly the ObjectMapper used gets customized somehow, disabling MixIns or something.

If you're still experiencing the issues, please provide a reproducible test case

@cvgaviao
Copy link

@frantuma, I'm in a rush here and I downgraded the version in order to keep things running ok.

I was not able to find any Serialization test in this code, just found Deserialization ones. Could you point it to me? I'll try to look at it, and if were necessary to create a reproducer this weekend.

@frantuma
Copy link
Member Author

@cvgaviao e.g. this test

@bdzzaid
Copy link

bdzzaid commented Sep 28, 2020

@cvgaviao I produce the same issue. I downgrade my swagger-core version to 2.1.3 to resolve my issue.

My point of view can be wrong, but I think the issue is in this class :
modules/swagger-models/src/main/java/io/swagger/v3/oas/models/media/Schema.java

When the boolean exampleSetFlag is a primitive field and not a Boolean object, the ObjectMapper will always serialize the boolean value (false if not set, true if the method public void setExample(Object example) is called.

ctasada pushed a commit to ctasada/springwolf-core that referenced this pull request May 12, 2023
Fixes springwolf#169

The `exampleSetFlag` and `types` properties belong to `swagger-core` internals and are not part of the AsyncAPI specification.

See swagger-api/swagger-core#3637 (comment) for some details.

This PR replaces the custom JSON ObjectMapper by the `swagger-core` one, which already contains all the needed `mixins` to properly serialize the specification.

Fixes springwolf#169 for Json Serialization
ctasada pushed a commit to ctasada/springwolf-core that referenced this pull request May 13, 2023
Fixes springwolf#169

The `exampleSetFlag` and `types` properties belong to `swagger-core` internals and are not part of the AsyncAPI specification.

See swagger-api/swagger-core#3637 (comment) for some details.

This PR replaces the custom JSON ObjectMapper by the `swagger-core` one, which already contains all the needed `mixins` to properly serialize the specification.

Fixes springwolf#169 for Json Serialization
timonback added a commit to springwolf/springwolf-core that referenced this pull request May 27, 2023
* fix: Fixed JSON serializer to not leak unintended values

Fixes #169

The `exampleSetFlag` and `types` properties belong to `swagger-core` internals and are not part of the AsyncAPI specification.

See swagger-api/swagger-core#3637 (comment) for some details.

This PR replaces the custom JSON ObjectMapper by the `swagger-core` one, which already contains all the needed `mixins` to properly serialize the specification.

Fixes #169 for Json Serialization

* chore: Use swagger objectmapper

The swagger objectmapper uses jackson underneath.
Besides registering serializers, also the mapper is configured automatically.

---------

Co-authored-by: Timon Back <timon.back+git@gmail.com>
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

Successfully merging this pull request may close these issues.

None yet

3 participants