Skip to content

Components fields name too restrictive? #1387

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

Open
PerthCharern opened this issue Oct 23, 2017 · 2 comments
Open

Components fields name too restrictive? #1387

PerthCharern opened this issue Oct 23, 2017 · 2 comments
Labels
clarification requests to clarify, but not change, part of the spec examples requests for more or better examples in the specification

Comments

@PerthCharern
Copy link
Contributor

Components fields name currently has this regex as restrictions: ^[a-zA-Z0-9\.\-_]+$
This was mainly discussed and agreed on in #634.

I found this restriction a little too restrictive. I'd imagine that for the Schemas part of the component, most people will use class names as field names. Allowing the period (.) is good because that allows you to add namespace to class name Namespace.ClassName.

However, quite a number of languages have generics and APIs can have request body that are of type implementing generics. The current allowed characters make it very difficult to represent class name that is derived from generic type. The most intuitive (I think) way to represent generic class name as string is to use some kind of brackets/parentheses Namespace.GenericClassName(AnotherClassName). Of course, one can bypass this by using the allowed underscore or hyphen instead, but that just looks plain ugly.

Should we allow parentheses and/or brackets?

@PerthCharern PerthCharern changed the title Components fields name example too restrictive? Components fields name too restrictive? Oct 23, 2017
@MikeRalphson
Copy link
Member

MikeRalphson commented Jan 8, 2018

Only the top-level schema object name must conform to the components key regex.

Is it possible you could do something like

components:
  schemas:
    container:
     type: object
     properties:
       namespace.generic(type):
         type: ...

or

components:
  schemas:
    namespace:
     type: object
     properties:
       generic(type):
         type: ...

and use a $ref nested through the container/namespace object, e.g.:

$ref: '/components/schemas/container/namespace.generic(type)'
  

@zdne
Copy link

zdne commented Jun 10, 2019

It would be good to be more explicit in the spec as this is confusing restriction for many.

@handrews handrews added the clarification requests to clarify, but not change, part of the spec label Jan 29, 2024
@ralfhandl ralfhandl added the examples requests for more or better examples in the specification label Aug 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clarification requests to clarify, but not change, part of the spec examples requests for more or better examples in the specification
Projects
None yet
Development

No branches or pull requests

5 participants