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

Adds default property values in ASP .NET Core models #3369

Merged
merged 2 commits into from
Jul 18, 2019

Conversation

james-beer
Copy link
Contributor

PR checklist

  • Read the contribution guidelines.
  • Ran the shell script under ./bin/ to update Petstore sample so that CIs can verify the change. (For instance, only need to run ./bin/{LANG}-petstore.sh, ./bin/openapi3/{LANG}-petstore.sh if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in .\bin\windows\. If contributing template-only or documentation-only changes which will change sample output, be sure to build the project first.
  • Filed the PR against the correct branch: master, 4.1.x, 5.0.x. Default: master.
  • Copied the technical committee to review the pull request if your PR is targeting a particular programming language.

Description of the PR

Changes

Tests

  • ./run-in-docker.sh mvn package successfully builds & runs tests.
  • ./run-in-docker.sh generate ... produces the following.
Schema
openapi: '3.0.0'
info:
  version: 1.0.0
  title: API with Default Values
servers:
  - url: http://localhost:8080
paths:
  /test:
    post:
      operationId: testDefaults
      requestBody:
        required: true
        content:
          application/json:
            schema:
              '$ref': '#/components/schemas/Payload'
      responses:
        '200':
          description: Ok
components:
  schemas:
    Payload:
      type: object
      properties:
        stringProp:
          type: string
          default: foo
        intProp:
          type: integer
          default: 123
        floatProp:
          type: number
          format: float
          default: 1.23
        doubleProp:
          type: number
          format: double
          default: 1.234
        decimalProp:
          type: number
          format: decimal
          default: 1.2345
        enumProp:
          type: string
          enum: [One, Two, Three]
          default: Two
Generated model properties
[DataContract]
public partial class Payload : IEquatable<Payload>
{ 
    /// <summary>
    /// Gets or Sets StringProp
    /// </summary>
    [DataMember(Name="stringProp", EmitDefaultValue=false)]
    public string StringProp { get; set; } = "foo";

    /// <summary>
    /// Gets or Sets IntProp
    /// </summary>
    [DataMember(Name="intProp", EmitDefaultValue=false)]
    public int? IntProp { get; set; } = 123;

    /// <summary>
    /// Gets or Sets FloatProp
    /// </summary>
    [DataMember(Name="floatProp", EmitDefaultValue=false)]
    public float? FloatProp { get; set; } = 1.23F;

    /// <summary>
    /// Gets or Sets DoubleProp
    /// </summary>
    [DataMember(Name="doubleProp", EmitDefaultValue=false)]
    public double? DoubleProp { get; set; } = 1.234D;

    /// <summary>
    /// Gets or Sets DecimalProp
    /// </summary>
    [DataMember(Name="decimalProp", EmitDefaultValue=false)]
    public decimal? DecimalProp { get; set; } = 1.2345M;

    /// <summary>
    /// Gets or Sets EnumProp
    /// </summary>
    [DataMember(Name="enumProp", EmitDefaultValue=false)]
    public EnumPropEnum? EnumProp { get; set; } = EnumPropEnum.TwoEnum;
}

Reviewers

@mandrean, @jimschubert

@wing328 wing328 merged commit 29a85d5 into OpenAPITools:master Jul 18, 2019
@wing328
Copy link
Member

wing328 commented Jul 18, 2019

@james-beer thanks for the contribution, which has been merged into master.

@wing328
Copy link
Member

wing328 commented Aug 10, 2019

@james-beer thanks for the PR, which has been included in the 4.1.0 release: https://twitter.com/oas_generator/status/1160000504455319553

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

Successfully merging this pull request may close these issues.

2 participants