-
Notifications
You must be signed in to change notification settings - Fork 6k
how to put parameter default value into generated code in swagger #6782
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
Comments
i use swagger2.0 |
Please try the latest master (2.3.0), which has better support for default values. SNAPSHOT version can be found in the README |
@wing328 hi, i use 2.3.0 to generate java code, the default value is generated in DevelopersApi.md file, but not in java code. |
I don't know about how the Java generator is supposed to work, but according to https://swagger.io/unlocking-the-spec-the-default-keyword/ the client does not need to set the default; it is the server that should assume the default value when it is not received by the client. So it shouldn't be necessary to set the default on the client when communicating to a server that is following the spec appropriately. |
@jonschoning thanks,i use swagger3.0,and the swagger-codegen-cli-3.0.0-20171009.075709-6.jar,my command is |
@jonschoning is right in saying that the API client does not take the default value ( |
You may want to double check the spec. |
@wing328 thanks,missing swagger input or config! may be a bug |
@wangyiran125 can you try the 2.3.0 SNAPSHOT instead? |
@wing328 tried 2.3.0,but the same exception when i use swagger 3.0 Exception in thread "main" java.lang.RuntimeException: missing swagger input or config! |
@wangyiran125 can you please share the spec (e.g. via gist.github.com)? |
Is there an update on the issue? It's not an template-issue. I've used a debugger to verify the Here's an enhanced operation of the pet store having the issue: /pets:
get:
summary: List all pets
operationId: listPets
tags:
- petstore
parameters:
- name: limit
in: query
description: How many items to return at one time (max 100)
required: false
schema:
type: integer
minimum: 1
maximum: 100
default: 20
responses:
'200':
description: A paged array of pets
headers:
x-next:
description: A link to the next page of responses
schema:
type: string
content:
application/json:
schema:
$ref: "#/components/schemas/Pets" |
hi @dfrommi |
Hi @HugoMario Took a bit now to test it, because I'm using a custom generator and had to fix some things for the update. Yes, it is working with version 3.0.19 Thanks a lot and sorry for the confusion. |
swagger parameter default is not in generated code. for example:
paths:
/user/refresh.json:
post:
operationId: refresh
description: |
By passing in the appropriate options, you can search for
available inventory in the system
produces:
- application/json
consumes:
- application/x-www-form-urlencoded
parameters:
- name: "RC-App-Key"
in: "header"
description: appkey..
required: true
default: "abc"
type: "string"
the generated code like
public class DevelopersApiTest {
private final DevelopersApi api = new DevelopersApi();
@test
public void refreshTest() throws ApiException {
String rcAppKey = null;
Common response = api.refresh(rcAppKey);
}
the rcAppKey is null,but i want it be the default value "abc",like:
String rcAppKey = "abc";
Common response = api.refresh(rcAppKey);
the default value is not in generated code,but in .md file,how to put the default value into the code?
The text was updated successfully, but these errors were encountered: