Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Merge requests
  • !3369

Adds default property values in ASP .NET Core models

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Administrator requested to merge github/fork/james-beer/aspnetcore-model-defaults into master Jul 15, 2019
  • Overview 0
  • Commits 2
  • Pipelines 0
  • Changes 3

Created by: james-beer

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

  • Addresses #3359 (closed)
  • Also fixes a small syntax error in docker-entrypoint.sh.

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

Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: github/fork/james-beer/aspnetcore-model-defaults