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

optional() is not working in OpenAPI 3 #213

Open
tabuyos opened this issue Nov 22, 2022 · 2 comments
Open

optional() is not working in OpenAPI 3 #213

tabuyos opened this issue Nov 22, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@tabuyos
Copy link

tabuyos commented Nov 22, 2022

First of all thank you very much for your contribution on rest docs.

Here is my debug screenshot

image

and section of resource.json

"requestFields" : [{
      "attributes" : { },
      "description" : "",
      "ignored" : false,
      "path" : "nickname",
      "type" : "STRING",
      "optional" : false
    }, {
      "attributes" : { },
      "description" : "",
      "ignored" : false,
      "path" : "avatar",
      "type" : "STRING",
      "optional" : true
    }, {
      "attributes" : { },
      "description" : "",
      "ignored" : false,
      "path" : "gender",
      "type" : "NUMBER",
      "optional" : true
    } ]

and section of openapi3.yaml

    UserSignUpMessage:
      title: UserSignUpMessage
      type: object
      properties:
        gender: {type: number, description:}
        avatar: {type: string, description: }
        nickname: {type: string, description:}

Each section is relatively complete, I have read #90 #172 that It doesn't seem to help me much. I'm not sure if I'm missing something, or doing something stupid

:)

@tabuyos
Copy link
Author

tabuyos commented Nov 23, 2022

I read the relevant source code carefully and found that the required properties is not filled with optional(), on the contrary, this should be a very complicated process. My unit test uses Map.class to pass and receive json parameters, it cannot be constructed using ConstrainedFields relevant constraints, maybe I missed something... tell me if you know please.

For this problem, I found a compromise solution after reading the source code

...
// define a function
protected Attributes.Attribute required() {
    List<Constraint> constraints = Lists.newArrayList(new Constraint("javax.validation.constraints.NotNull", Collections.emptyMap()));
    return Attributes.key("validationConstraints").value(constraints);
  }
...
// and use it.
fieldWithPath("field").attributes(required()).description("description")
...

Maybe there is a better solution...

My English is not as fluent as Chinese, I'm sorry for that.

Thanks again for your contribution.

@ozscheyge ozscheyge added the bug Something isn't working label Nov 23, 2022
@xeromank
Copy link
Contributor

#244

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants