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

OpenAPI 3 lost schema properties required list. #90

Closed
abcfy2 opened this issue Mar 26, 2019 · 4 comments · Fixed by #183
Closed

OpenAPI 3 lost schema properties required list. #90

abcfy2 opened this issue Mar 26, 2019 · 4 comments · Fixed by #183
Labels
bug Something isn't working

Comments

@abcfy2
Copy link

abcfy2 commented Mar 26, 2019

Here is the snippet from require.json:

  "response" : {
    "status" : 200,
    "contentType" : "application/json",
    "headers" : [ ],
    "responseFields" : [ {
      "attributes" : { },
      "description" : "OSS的access key id",
      "ignored" : false,
      "path" : "accessKeyId",
      "type" : "STRING",
      "optional" : false
    }, {
      "attributes" : { },
      "description" : "OSS的权限矩阵",
      "ignored" : false,
      "path" : "policy",
      "type" : "STRING",
      "optional" : false
    }, {
      "attributes" : { },
      "description" : "OSS认证成功后的签名",
      "ignored" : false,
      "path" : "signature",
      "type" : "STRING",
      "optional" : false
    }, {
      "attributes" : { },
      "description" : "有权限上传的目录",
      "ignored" : false,
      "path" : "dir",
      "type" : "STRING",
      "optional" : false
    }, {
      "attributes" : { },
      "description" : "OSS访问主机",
      "ignored" : false,
      "path" : "host",
      "type" : "STRING",
      "optional" : false
    }, {
      "attributes" : { },
      "description" : "授权过期时间",
      "ignored" : false,
      "path" : "expire",
      "type" : "NUMBER",
      "optional" : false
    }, {
      "attributes" : { },
      "description" : "用于外部访问的CDN URL(可空)",
      "ignored" : false,
      "path" : "cdnUrl",
      "type" : "STRING",
      "optional" : true
    } ],

But convert to openapi3.yaml lost the optional field:

components:
  schemas:
    api-getUploadAuthority2026114897:
      type: object
      properties:
        accessKeyId:
          type: string
          description: OSS的access key id
        signature:
          type: string
          description: OSS认证成功后的签名
        cdnUrl:
          type: string
          description: 用于外部访问的CDN URL(可空)
        expire:
          type: number
          description: 授权过期时间
        host:
          type: string
          description: OSS访问主机
        dir:
          type: string
          description: 有权限上传的目录
        policy:
          type: string
          description: OSS的权限矩阵

OpenAPI 3 has required property list. See: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#schema-object

I hope optional from resource.json could render to required to openapi3.yaml.

components:
  schemas:
    api-getUploadAuthority2026114897:
      type: object
      required:                  # <======== Add required list except isOptioanl() is true
        - accessKeyId
        - signature
        - expire
        - host
        - dir
        - policy
      properties:
        accessKeyId:
          type: string
          description: OSS的access key id
        signature:
          type: string
          description: OSS认证成功后的签名
        cdnUrl:
          type: string
          description: 用于外部访问的CDN URL(可空)
        expire:
          type: number
          description: 授权过期时间
        host:
          type: string
          description: OSS访问主机
        dir:
          type: string
          description: 有权限上传的目录
        policy:
          type: string
          description: OSS的权限矩阵
@abcfy2 abcfy2 changed the title OpenAPI 3 lost schema properties required config. OpenAPI 3 lost schema properties required list. Mar 26, 2019
@mduesterhoeft
Copy link
Collaborator

This sounds like a very reasonable suggestion. No idea why we did not do it from the beginning. Any doubts @ozscheyge?

@mduesterhoeft mduesterhoeft added the enhancement New feature or request label Mar 26, 2019
@ozscheyge
Copy link
Contributor

Yeah, looks like an error, in the generation of the openapi 2 spec, we do exactly this!

@mduesterhoeft
Copy link
Collaborator

Strange - we use the same JsonSchema generator for openApi 2 and 3.

@mduesterhoeft
Copy link
Collaborator

At the moment the required property in the schema is set by introspecting bean validation constraints - https://github.com/ePages-de/restdocs-api-spec#documenting-bean-validation-constraints

We do not look at the optional field in the field descriptor. The question is, if we should do this.

See also https://github.com/ePages-de/restdocs-api-spec/blob/master/restdocs-api-spec-jsonschema/src/main/kotlin/com/epages/restdocs/apispec/jsonschema/JsonSchemaFromFieldDescriptorsGenerator.kt#L162

@mduesterhoeft mduesterhoeft pinned this issue Mar 28, 2019
@ozscheyge ozscheyge added bug Something isn't working and removed enhancement New feature or request labels Apr 28, 2021
TiboStev pushed a commit to TiboStev/restdocs-api-spec that referenced this issue Aug 3, 2021
ozscheyge pushed a commit that referenced this issue Aug 9, 2021
* handle size and required constraints on arrays

Fixes #90, #180

* apply review comments

Co-authored-by: tstevelinck <thibaud.stevelinck@soprabanking.com>
@ozscheyge ozscheyge unpinned this issue Aug 9, 2021
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

Successfully merging a pull request may close this issue.

3 participants