Skip to content

Various improvements to schema binding#745

Merged
graemerocher merged 6 commits intomicronaut-projects:masterfrom
altro3:fix_lost_example
Jun 27, 2022
Merged

Various improvements to schema binding#745
graemerocher merged 6 commits intomicronaut-projects:masterfrom
altro3:fix_lost_example

Conversation

@altro3
Copy link
Collaborator

@altro3 altro3 commented Jun 12, 2022

  • kotlin 1.7.0
  • Improved test for complex OpenAPIDefinition
  • Fixed lost default value in schema (on class level)
  • Fixed lost default, example, deprecated, accessMode properties, when use Schema on property level
  • Fixed rename property when use Schema on property level

@altro3 altro3 changed the title Fix lost example Fixex for schema Jun 12, 2022
@altro3 altro3 changed the title Fixex for schema Fixes for schema Jun 12, 2022
Comment on lines +1020 to +1090
Optional<io.swagger.v3.oas.annotations.media.Schema.AccessMode> schemaAccessMode = schemaAnn.get("accessMode", io.swagger.v3.oas.annotations.media.Schema.AccessMode.class);
if (schemaAccessMode.isPresent()) {
if (schemaAccessMode.get() == io.swagger.v3.oas.annotations.media.Schema.AccessMode.READ_ONLY) {
schemaToBind.setReadOnly(true);
schemaToBind.setWriteOnly(null);
} else if (schemaAccessMode.get() == io.swagger.v3.oas.annotations.media.Schema.AccessMode.WRITE_ONLY) {
schemaToBind.setReadOnly(false);
schemaToBind.setWriteOnly(null);
} else if (schemaAccessMode.get() == io.swagger.v3.oas.annotations.media.Schema.AccessMode.READ_WRITE) {
schemaToBind.setReadOnly(null);
schemaToBind.setWriteOnly(null);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not critical but this code can be written more cleanly with something like:

schemaAnn.enumValue("accessMode", io.swagger.v3.oas.annotations.media.Schema.AccessMode.class)
   .ifPresent(accessMode -> {
          switch(accessMode) {
               case READ_ONLY:
                        schemaToBind.setReadOnly(true);
                         schemaToBind.setWriteOnly(null);
                break;
               case WRITE_ONLY:
                        schemaToBind.setReadOnly(false);
                         schemaToBind.setWriteOnly(null);
                break;
          }
   });

Apart from that is setting write only to null correct?

Copy link
Collaborator Author

@altro3 altro3 Jun 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@graemerocher I don't now, sorry. This block copypasted from swagger lib

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@graemerocher Your proposal is not so simple, because would require making the schemaToBind variable finalized. In this case, I think that this block is better left as is.

изображение

…efault value ehn schema used on class level. Add rename property feature by schema name
@altro3
Copy link
Collaborator Author

altro3 commented Jun 23, 2022

@graemerocher Hi! Could anyone review my pull requests? Because I want to continue improve this module and now it's already 6 PR open from me and need to merge them so that there are fewer problems with conflicts

@graemerocher graemerocher changed the title Fixes for schema Various improvements to schema binding Jun 27, 2022
@graemerocher graemerocher merged commit f429bb2 into micronaut-projects:master Jun 27, 2022
@graemerocher
Copy link
Contributor

@altro3 was away last week, apologies for the delay

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.

2 participants