Skip to content

Commit

Permalink
Merge pull request #15 from eManPrague/fix/query_params
Browse files Browse the repository at this point in the history
🐛 Fix a query params to allow null and default val
  • Loading branch information
Del-S authored Apr 22, 2020
2 parents 290c434 + 9665c8d commit aa7be51
Show file tree
Hide file tree
Showing 8 changed files with 142 additions and 7 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Change Log
==========

## 2.1.1 (2020-04-22)

### Fixed
- `(jvm-retrofit)` an optional `@Query` parameter marked as not null in case of Kotlin generator. Now it is nullable.
- `(jvm-retrofit)` missing default value in a `@Query` parameter if is present in the yaml file.

## 2.1.0 (2020-04-16)

### Added
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# OpenApi 3 Codegen / Swagger

[ ![Download](https://api.bintray.com/packages/emanprague/maven/cz.eman.swagger.codegen/images/download.svg?version=2.0.1) ](https://bintray.com/emanprague/maven/cz.eman.swagger.codegen/2.0.1/link)
[ ![Download](https://api.bintray.com/packages/emanprague/maven/cz.eman.swagger.codegen/images/download.svg?version=2.1.1) ](https://bintray.com/emanprague/maven/cz.eman.swagger.codegen/2.1.1/link)

The Swagger codegen contains a template-driven engine to generate documentation, code for Java, Kotlin and Android such like Retrofit and Room. It is a fork of the https://github.com/OpenAPITools/openapi-generator with modifications

Expand All @@ -17,7 +17,7 @@ buildscript {

// Kotlin Gradle DSL
dependencies {
classpath("cz.eman.swagger:swagger-codegen:2.0.1")
classpath("cz.eman.swagger:swagger-codegen:2.1.1")
}
}
```
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ private object Versions {

const val retrofit = "2.6.0"
const val moshi = "1.9.2"
const val swaggerCodeGen = "2.1.0"
const val swaggerCodeGen = "2.1.1"
}

/* ============================= BUILD-PLUGINS ======================= */
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
org.gradle.jvmargs=-Xmx1536m

version=2.1.0
version=2.1.1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{#isQueryParam}}@Query("{{baseName}}") {{{paramName}}}: {{#collectionFormat}}{{#isCollectionFormatMulti}}{{{dataType}}}{{>opt_datatype}}{{/isCollectionFormatMulti}}{{^isCollectionFormatMulti}}{{{collectionFormat.toUpperCase}}}Params{{/isCollectionFormatMulti}}{{/collectionFormat}}{{^collectionFormat}}{{{dataType}}}{{>opt_datatype}}{{/collectionFormat}}{{/isQueryParam}}
1 change: 1 addition & 0 deletions lib/src/main/resources/kotlin-client/opt_datatype.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{#required}}{{#defaultValue}} = {{{defaultValue}}}{{/defaultValue}}{{/required}}{{^required}}{{#defaultValue}} = {{{defaultValue}}}{{/defaultValue}}{{^defaultValue}} ?= null{{/defaultValue}}{{/required}}
16 changes: 13 additions & 3 deletions sample/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,31 @@ configure<SwaggerCodeGenConfig> {
listOf(
SwaggerCodeGenTaskConfig(
inputFileName = "petstore.yaml",
outputFolderName = "one-of",
outputFolderName = "petstore",
additionalProperties = mapOf(
"apiPackage" to "cz.eman.swagger.api.petstore",
"modelPackage" to "cz.eman.swagger.api.petstore.model"
)
),
SwaggerCodeGenTaskConfig(
inputFileName = "petstore-opt-def-arg-api.yaml",
outputFolderName = "petstore-def-and-opt-query",
additionalProperties = mapOf(
"apiPackage" to "cz.eman.swagger.api.petstore.defoptapi",
"modelPackage" to "cz.eman.swagger.api.petstore.defoptapi.model"
)
)
)
}

val generatedOneOfSrcDir = File(buildDir, "openapi/one-of/src/main/kotlin")
val generatedPetStoreSrcDir = File(buildDir, "openapi/petstore/src/main/kotlin")
val generatedPetStoreDefOptApiQuerySrcDir = File(buildDir, "openapi/petstore-def-and-opt-query/src/main/kotlin")

sourceSets {
getByName("main").java.srcDirs(
"src/main/kotlin",
generatedOneOfSrcDir
generatedPetStoreSrcDir,
generatedPetStoreDefOptApiQuerySrcDir
)
getByName("test").java.srcDirs("src/test/kotlin")
}
Expand Down
117 changes: 117 additions & 0 deletions sample/openapi/petstore-opt-def-arg-api.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
openapi: "3.0.0"
info:
version: 1.0.0
title: Swagger Petstore
license:
name: MIT
servers:
- url: http://petstore.swagger.io/v1
paths:
/pets:
get:
summary: List all pets
operationId: listPets
tags:
- pets
parameters:
- name: limit
in: query
description: How many items to return at one time (max 100)
required: false
schema:
type: integer
format: int32
- name: loadAll
in: query
required: false
schema:
type: boolean
default: true
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"
default:
description: unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
post:
summary: Create a pet
operationId: createPets
tags:
- pets
responses:
'201':
description: Null response
default:
description: unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
/pets/{petId}:
get:
summary: Info for a specific pet
operationId: showPetById
tags:
- pets
parameters:
- name: petId
in: path
required: true
description: The id of the pet to retrieve
schema:
type: string
responses:
'200':
description: Expected response to a valid request
content:
application/json:
schema:
$ref: "#/components/schemas/Pet"
default:
description: unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
components:
schemas:
Pet:
type: object
required:
- id
- name
properties:
id:
type: integer
format: int64
name:
type: string
tag:
type: string
Pets:
type: array
items:
$ref: "#/components/schemas/Pet"
Error:
type: object
required:
- code
- message
properties:
code:
type: integer
format: int32
message:
type: string

0 comments on commit aa7be51

Please sign in to comment.