eclipse / microprofile-open-api

Microprofile open api
Apache License 2.0
131 stars 82 forks source link

Example object in Schema is always of String type #420

Closed dmi3coder closed 4 years ago

dmi3coder commented 4 years ago

The original issue was posted here: https://github.com/smallrye/smallrye-open-api/issues/300 I have a very simple User object where I have id field of type integer. I added example with specifying the type

public class User {

    @Schema(type = SchemaType.INTEGER, example = "1000")
    private Integer id;
... constructor, getters, and setters omitted
}

This generates a schema with an example as a string

    User:
      type: object
      properties:
        id:
          format: int32
          type: integer
          example: "1000"

Because of this in e.g Swagger UI when I'm prompted to fill in the example I have string type, users can think that it's mandatory to wrap integer into double-quotes.

By OpenAPI, an example can be any type of object(e.g integer, string, number), but currently, there's no way to specify that you want to parse this value into the required format. As I understand implementation doesn't know whether to parse this value or use it as a string.

As @MikeEdgar suggested: "Maybe the change could be to add to @ExampleObject a property boolean parseValue and support using that annotation from @Schema"

MikeEdgar commented 4 years ago

@dmi3coder - we discussed this in the Microprofile OpenAPI hangout last week and found that my suggestion to open this as a specification issue was a bit misguided. This is an implementation problem and your original issue in SmallRye is the best place to continue this discussion.

Basically, the implementation should be handling the parsing of the example string based on the type of the enclosing schema, which was your original thought. We would only want to go down the path of using @ExampleObject if multiple examples are necessary, and maybe not even then.

If you are in agreement, please go ahead and close this issue and we can continue working this as a change in smallrye-open-api.

dmi3coder commented 4 years ago

@MikeEdgar sounds great, thank you