Forum Discussion

fastdude7's avatar
fastdude7
New Contributor
7 years ago

Specifying types which are subset of String

Hi, I would like to specify an API which returns a FooId. A FooId is a 4 character String consisting of ascii alphanum chars.

When I end up generating my API I make it so that the FooId is not a wrapper for a string instead I just return:

{
    fooId: "abcd",
someThingElse: "a",
number: 2
}

Is it possible to specify in the swagger doc (openAPI) that:

  • A FooId should be treated like a string, no wrapping class for example.
  • While preserving the fact that it is a FooId so a client consuming the swagger doc knows which APIs really return strings and which ones are returning a FooId, so no information is lost.

Does the spec support this?

 

full disclosure I asked a similar question on stack overflow which got no responses https://stackoverflow.com/questions/55915610/does-swagger-openapi-support-declaring-types-that-are-sub-types-of-string-or-o