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