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

Is there a known workaround for handling an array of string/enum? #87

Closed
lzhoucs opened this issue Mar 25, 2019 · 3 comments · Fixed by #130
Closed

Is there a known workaround for handling an array of string/enum? #87

lzhoucs opened this issue Mar 25, 2019 · 3 comments · Fixed by #130

Comments

@lzhoucs
Copy link
Contributor

lzhoucs commented Mar 25, 2019

I have an array of simple enum called weathers. Although I can get to the array itself:

fieldWithPath("weathers").type(JsonFieldType.ARRAY).description("an array of weathers")

I can't get to the element inside it currently due to the exact same limitation as: spring-projects/spring-restdocs#505. As such, I got the following openapi3 spec:

weathers:
          type: array
          description: an array of weathers
          items:
            oneOf:
            - type: object
            - type: boolean
            - type: string
            - type: number

It seems the relevant logic is added in this PR: #62 as "default behavior".

Here is a minified demo: https://github.com/lzhoucs/spring-restdocs/tree/87-demo/samples/junit5

What I would like to see is as follows:

weathers:
          type: array
          description: an array of weathers
          items:
            type: string
            enum: [SPRING, SUMMER...]

Is there any workaround to get close to what I expected above?

lzhoucs added a commit to lzhoucs/spring-restdocs that referenced this issue Mar 25, 2019
@mduesterhoeft
Copy link
Contributor

mduesterhoeft commented Mar 28, 2019

Yes this is a limitation that is originating in spring-restdocs. We just have the json type of a field and we do not know any more. We could try to extend the field descriptor to add the enum values. The descriptor itself has a dynamic attributes field that we could use to add the hint that the field is an enum field and could also add the list of possible values. We could then make use of this knowledge in JsonSchemaFromFieldDescriptorsGenerator to add the enum type to the property.

Do you want to give it a try?

@ozscheyge
Copy link
Contributor

ozscheyge commented Feb 10, 2020

With the api-spec now supporting enum values, the generators (gradle plugins) would still need to be adapted to leverage the change.

@thowimmer
Copy link
Contributor

Yes I guess I missed that. I will implement the support in the generators in the next few days and open a PR.

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 a pull request may close this issue.

4 participants