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

Render JsonSchema constraints #42

Closed
11 tasks done
RomanHotsiy opened this issue Apr 26, 2016 · 18 comments
Closed
11 tasks done

Render JsonSchema constraints #42

RomanHotsiy opened this issue Apr 26, 2016 · 18 comments
Assignees

Comments

@RomanHotsiy
Copy link
Member

RomanHotsiy commented Apr 26, 2016

  • readOnly
  • minLength
  • maxLength
  • pattern
  • minItems
  • maxItems
  • multipleOf
  • defaults
  • file payload
  • readOnly - don't show readOnly fields in request schema
  • No need to mark readOnly in response

to be continued...

@RomanHotsiy RomanHotsiy self-assigned this Apr 26, 2016
@RomanHotsiy RomanHotsiy added this to the Rebilly release milestone Apr 26, 2016
RomanHotsiy added a commit that referenced this issue Apr 27, 2016
@RomanHotsiy RomanHotsiy changed the title RenderJsonSchema constrains Render JsonSchema constrains Apr 28, 2016
@RomanHotsiy
Copy link
Member Author

Defaults are supported for primitive types only. Need to add this to the known issues

@RomanHotsiy RomanHotsiy modified the milestones: v1.0, Rebilly release May 31, 2016
@MikeRalphson
Copy link
Contributor

@RomanGotsiy Should dividedBy actually be multipleOf? I don't recognise it from the Swagger spec or JSON Schema draft 4.

@RomanHotsiy
Copy link
Member Author

@MikeRalphson yes, you're right. Updated.
Thanks

@adamaltman adamaltman changed the title Render JsonSchema constrains Render JsonSchema constraints Oct 4, 2016
@nakedible-p
Copy link

I know this is marked as post v1.0, but I'd like to mention that we use "pattern" a lot in our API definitions - almost every field is solely determined by pattern - because it is a very simple way to document what kind of values are accepted. Showing that somehow in the rendered documentation would be important for us.

@RomanHotsiy
Copy link
Member Author

@nakedible-p, pattern should be easy to add. I will try to have it done for the next minor release

@RomanHotsiy
Copy link
Member Author

@nakedible-p finally get to this.
What do you think of the following representation?
image

Maybe you have better idea?

@nakedible-p
Copy link

I think it is perfect. Slashes are the universal regexp indicator.

@RomanHotsiy
Copy link
Member Author

Great, hopefully will publish new minor release with this today. Max - tomorrow.

RomanHotsiy added a commit that referenced this issue Nov 1, 2016
@RomanHotsiy
Copy link
Member Author

@nakedible-p New version is released.

@fgabolde
Copy link

Hello, any hope for minItems and maxItems ? There is already support for minLength and maxLength which are basically the same thing for strings.

@RomanHotsiy
Copy link
Member Author

@fgabolde do you have any ideas of how this may look in ReDoc? Similar to minLength and maxLength?

@fgabolde
Copy link

fgabolde commented Mar 9, 2018

Yeah, probably. Right now a size constraint on a string is represented like this:

  • [ 2 .. 8 ] characters with both constraints set
  • <= 8 characters, max only
  • >= 2 characters, min only

Just replacing "characters" with "items" sounds good to me.

@fgabolde
Copy link

I don't see the pattern in strings that are used as array items, e.g.:

# definition
HTTPSURL:
  type: string
  format: uri
  pattern: "^https?"
# this one displays "/^https?/" as expected
Thing:
  type: object
  properties:
    single:
      $ref: '#/HTTPSURL'
# this one does not
ManyThings:
  type: object
  properties:
    multiple:
      type: array
      items:
        $ref: '#/HTTPSURL'

I do see the <uri> from the format in both cases, and if I add minLength it works too.

This is Redoc 1.21.2.

RomanHotsiy pushed a commit that referenced this issue Nov 5, 2018
…#700)

According to #42 , `minItems` and `maxItems` are not yet rendered in the documentation.
This pull request shows the humazined form of `minItems` and `maxItems` next to the type description.
The [suggestion of fgabolde](#42 (comment)) is followed and "characters" is simply replaced with "items".

![image](https://user-images.githubusercontent.com/1814807/47999845-0a13f900-e104-11e8-9ddc-adab701ec0bb.png)

Some examples are added to the demo.
@handrews
Copy link

handrews commented Feb 19, 2019

@RomanGotsiy Thank you for the fantastic documentation tool!

However, I'm confused about readOnly (which is more a result of how OpenAPI has specified it than how ReDoc handles is, which I understand flows from that definition- that said, it would be great if there were a bit more flexibility).

For a POST-to-create I can understand stripping out readOnly fields, although not all POST requests have those semantics so it's a somewhat shaky assumption.

For GET and PUT, the HTTP semantics are that the GET response and PUT request are both representations of the target resource, so you should be able to do a GET, modify some fields, and PUT it right back. As long as you don't change the readOnly fields, it should be fine (yes, I realize that OpenAPI doesn't like this, but it's a SHOULD and not a MUST and it's ridiculously burdensome to make clients strip out fields when doing GET-modify-PUT).

Similarly, if I want to make a copy of a resource, I'll do a GET of it, tweak it, and then POST the tweaked version back to the collection.

In order to make this behavior clear, the readOnly constraint should be rendered on both requests and responses. Would you be open to some sort of option for displaying it as a constraint? I would be happy to write a PR.

@RomanHotsiy
Copy link
Member Author

@handrews yeah, you're right. That's an incorrect assumption 🙈

I think we can add configuration options to disable stripping out and mark fields as readOnly/readWrite instead.

I will try to do in once I find some time. But your PR would be much appreciated!

@handrews
Copy link

handrews commented Mar 2, 2019

@RomanGotsiy I'll see if I can put something together in the next week-ish. I took a look and it looks reasonably straightforward- nice job piping the settings through.

Looks like the request body behavior is set in components/Parameters/Parameters.tsx, response body in components/Responses/ResponseDetails.tsx and examples for both requests and responses in services/models/MediaType.ts. And associated tests. Let me know if you can think of any other places offhand.

@calamarico
Copy link

@fgabolde I also have the problem that I can't see the pattern in Array of Strings. Did you find the problem with that?

@AlexVarchuk
Copy link
Collaborator

All constraints were added and the issue is too old. I close that. If someone wants to report supporting additional JsonSchema constraints, feel free to open a new issue.

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

7 participants