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

Question : How to hook into schema object generation #20

Open
snimavat opened this issue Nov 1, 2017 · 12 comments
Open

Question : How to hook into schema object generation #20

snimavat opened this issue Nov 1, 2017 · 12 comments

Comments

@snimavat
Copy link

snimavat commented Nov 1, 2017

I couldnt find any docs so have to ask the question here.

What I am looking for, is to hook into schema object generation.
https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#schemaObject

So that we can generate the schema object for domain classes based on mappings and constraints etc. And can specify what fields are required, pattern, description, default value, min max and other constraits etc.

Thanks

@snimavat
Copy link
Author

snimavat commented Nov 1, 2017

I guess what i am looking for is probably ModelBuilderPlugin or may be OperationModelsProvider but dont know where to start..
Any help would be appreciated. @dilipkrish

@dilipkrish
Copy link
Member

There is already support for certain annotations that influence model generation and properties. All swagger annotations are supported. E.g. ApiModelProperty. In addition where applicable Jackson annotations are supported. Cannot really say without a specific example.

Could you perhaps describe what you’re ttrying to do

@snimavat
Copy link
Author

snimavat commented Nov 2, 2017

@dilipkrish - What I am looking for is, to hook grails constraints into springfox

Given the Grails domain class (Model)

class Book {
   String name
   BigDecimal price
   Author author

   static constraints = {
    author nullable:false
    name nullable:false, default: "xxx"
   price nullable: false, max: 1000.00, min: 50.00, default:"xxx"
 }
}

From this, I can see, the model has all the information it needs regarding its properties.
And I dont want to use ApiModelProperty annotation. (Currently Adding ApiModelProperty(required=true) to title, for example, doesnt make the title required anyway)

I am looking for integration point in springfox, that will let me include the above information in model schema. Eg make a field required, default value, min and max values etc.

Also, looking for a way to make the author a $ref instead of authorId (Which is what it does currently)

I know the grails side, but dont know springfox enough to combine this two things togather.

Grails constraints: https://docs.grails.org/3.1.1/ref/Constraints/Usage.html
Thanks

@dilipkrish
Copy link
Member

So your need to implement the ModelPropertyBuilderPlugin and hook in to the GrailsDomainClass to infer the constraints. Sorry that I’m not intimately familiar with grails but I know it’s accesible if you pull in the right beans. You can dig in further if you’d like and let me know if you have any questions.

@snimavat
Copy link
Author

snimavat commented Nov 3, 2017

Okay, will try with ModelPropertyBuilder.
I am quite familiar with Grails.. dont know springfox api enough to hook into

Given the way grails support is currently implemented, I see that Grails domains are configured with Alternate type rules. Would i need to change any thing there ? Or just ModelPropertyBuilder should be enough.

@dilipkrish
Copy link
Member

Oh that’s right. It is still possible to do it with the plugin I believe but You may need to enhance the rule/convention to support for what your needing to do. In which case u may need to incorporate it as a PR. Im on vacation and don’t have the code in front of me, sorry. Let me know if have any questions I’ll be gals to help.

@snimavat
Copy link
Author

snimavat commented Nov 6, 2017

@dilipkrish When using AlternateTypePropertyBuilder and AlternateTypeBuilder
How do we specify some properties as required, min, max etc ? ModelPropertyAnnotation on original type doesnt seem to have any effect.

@dilipkrish
Copy link
Member

I think that is an enhancement that is in the works in the main springfox library. ModelProperty/ModelPropertyBuilder is missing those properties

@ibmsoft
Copy link

ibmsoft commented Jun 21, 2018

@snimavat When using AlternateTypePropertyBuilder and AlternateTypeBuilder
How do we specify some properties as required, min, max etc ?

@dilipkrish
Copy link
Member

You can add a Size annotation by using the withAnnotations

@ibmsoft
Copy link

ibmsoft commented Jun 22, 2018

@dilipkrish thanks for your quick replay
i find the withAnnotations method ,but i does not find the correct way ,would you like show me the code(i just want add some description to the model)

@dilipkrish
Copy link
Member

I'll have to research this. Do you perhaps have a breaking test?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants