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

Support model references directly to primitives #243

Closed
fehguy opened this issue May 12, 2016 · 8 comments
Closed

Support model references directly to primitives #243

fehguy opened this issue May 12, 2016 · 8 comments
Milestone

Comments

@fehguy
Copy link
Contributor

fehguy commented May 12, 2016

A model like this:

swagger: '2.0'
definitions:
  User:
    $ref: 'BaseUser'
  BaseUser:
    type: string

Is legal but currently not supported in the parser.

@fehguy fehguy added this to the v1.1.0 milestone May 12, 2016
@fehguy
Copy link
Contributor Author

fehguy commented May 12, 2016

Also affects swagger-api/swagger-codegen#2314

@webron
Copy link
Contributor

webron commented May 17, 2016

Did you mean the following?

swagger: '2.0'
definitions:
  User:
    $ref: '#/definitions/BaseUser'
  BaseUser:
    type: string

@fehguy
Copy link
Contributor Author

fehguy commented Oct 27, 2016

This has been implemented

@fehguy fehguy closed this as completed Oct 27, 2016
@sreeshas
Copy link

@fehguy Do you have more details on implementation? Is there a PR which we can refer?

@jimvmathews
Copy link

@fehguy - Can you point us to the PR or test that has fixed this issue? I have pulled this latest version into the swagger-codegen and the problem swagger-api/swagger-codegen#3483 is not resolved.

@robsdudeson
Copy link

Would be interested in details as well. I'm seeing the same issue on master.

fehguy added a commit that referenced this issue Mar 23, 2017
@fehguy
Copy link
Contributor Author

fehguy commented Mar 23, 2017

see 5e98486

fehguy added a commit that referenced this issue Mar 23, 2017
@jbx1
Copy link

jbx1 commented Mar 18, 2018

While direct references to primitives are supported, none of the validation specifiers associated with it are carried over.

For example:

     email:
        type: string
        pattern: '^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$'
        description: Email address of the customer.
     mobile:
        $ref: '#/definitions/Mobile'

with the definition:

 Mobile:
    type: string
    pattern: '^\\+[1-9][0-9]{3,14}$'
    description: The mobile number in E.164 format.

Using swagger-codegen version 2.3.1 for spring-boot generates the right validation annotations and javadoc for email:

  /**
   * Email address of the customer.
   * @return email
  **/
  @ApiModelProperty(value = "Email address of the customer.")
@Pattern(regexp="^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\\.[a-zA-Z0-9-]+)*$") 
  public String getEmail() {
    return email;
  }

But not for the mobile property:

/**
   * Get mobile
   * @return mobile
  **/
  @ApiModelProperty(required = true, value = "")
  @NotNull
  public String getMobile() {
    return mobile;
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants