Skip to content

Commit

Permalink
[haskell-http-client] default InlineMimeTypes=true (#7534)
Browse files Browse the repository at this point in the history
- default CLI option InlineMimeTypes to True, since it produces cleaner code

- update bounds on dependancies
  • Loading branch information
jonschoning authored and wing328 committed Feb 1, 2018
1 parent 6b9d38d commit 2d0bafb
Show file tree
Hide file tree
Showing 27 changed files with 575 additions and 595 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public class HaskellHttpClientCodegen extends DefaultCodegen implements CodegenC

static final String MEDIA_TYPE = "mediaType";
static final String MIME_NO_CONTENT = "MimeNoContent";
static final String MIME_ANY = "MimeAny";

// vendor extensions
static final String X_ALL_UNIQUE_PARAMS = "x-allUniqueParams";
Expand Down Expand Up @@ -215,7 +216,7 @@ public HaskellHttpClientCodegen() {
knownMimeDataTypes.put("application/octet-stream", "MimeOctetStream");
knownMimeDataTypes.put("multipart/form-data", "MimeMultipartFormData");
knownMimeDataTypes.put("text/plain", "MimePlainText");
knownMimeDataTypes.put("*/*", "MimeAny");
knownMimeDataTypes.put("*/*", MIME_ANY);

importMapping.clear();

Expand All @@ -235,7 +236,7 @@ public HaskellHttpClientCodegen() {
cliOptions.add(CliOption.newBoolean(PROP_GENERATE_MODEL_CONSTRUCTORS, "Generate smart constructors (only supply required fields) for models").defaultValue(Boolean.TRUE.toString()));
cliOptions.add(CliOption.newBoolean(PROP_GENERATE_ENUMS, "Generate specific datatypes for swagger enums").defaultValue(Boolean.TRUE.toString()));
cliOptions.add(CliOption.newBoolean(PROP_GENERATE_FORM_URLENCODED_INSTANCES, "Generate FromForm/ToForm instances for models that are used by operations that produce or consume application/x-www-form-urlencoded").defaultValue(Boolean.TRUE.toString()));
cliOptions.add(CliOption.newBoolean(PROP_INLINE_MIME_TYPES, "Inline (hardcode) the content-type and accept parameters on operations, when there is only 1 option").defaultValue(Boolean.FALSE.toString()));
cliOptions.add(CliOption.newBoolean(PROP_INLINE_MIME_TYPES, "Inline (hardcode) the content-type and accept parameters on operations, when there is only 1 option").defaultValue(Boolean.TRUE.toString()));


cliOptions.add(CliOption.newString(PROP_MODEL_DERIVING, "Additional classes to include in the deriving() clause of Models"));
Expand Down Expand Up @@ -385,7 +386,7 @@ public void processOpts() {
if (additionalProperties.containsKey(PROP_INLINE_MIME_TYPES)) {
setInlineMimeTypes(convertPropertyToBoolean(PROP_INLINE_MIME_TYPES));
} else {
setInlineMimeTypes(false);
setInlineMimeTypes(true);
}

if (additionalProperties.containsKey(PROP_GENERATE_LENSES)) {
Expand Down Expand Up @@ -836,7 +837,9 @@ private void processProducesConsumes(CodegenOperation op) {
private void processInlineConsumesContentType(CodegenOperation op, Map<String, String> m) {
if (op.vendorExtensions.containsKey(X_INLINE_CONTENT_TYPE)) return;
if ((boolean) additionalProperties.get(PROP_INLINE_MIME_TYPES)
&& op.consumes.size() == 1) {
&& op.consumes.size() == 1
&& op.consumes.get(0).get(X_MEDIA_DATA_TYPE) != MIME_ANY
&& op.consumes.get(0).get(X_MEDIA_DATA_TYPE) != MIME_NO_CONTENT) {
op.vendorExtensions.put(X_INLINE_CONTENT_TYPE, m);
for (CodegenParameter param : op.allParams) {
if (param.isBodyParam && param.required) {
Expand All @@ -848,7 +851,9 @@ private void processInlineConsumesContentType(CodegenOperation op, Map<String, S

private void processInlineProducesContentType(CodegenOperation op, Map<String, String> m) {
if ((boolean) additionalProperties.get(PROP_INLINE_MIME_TYPES)
&& op.produces.size() == 1) {
&& op.produces.size() == 1
&& op.produces.get(0).get(X_MEDIA_DATA_TYPE) != MIME_ANY
&& op.produces.get(0).get(X_MEDIA_DATA_TYPE) != MIME_NO_CONTENT) {
op.vendorExtensions.put(X_INLINE_ACCEPT, m);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Swagger Auto-Generated [http-client](https://www.stackage.org/lts-9.0/package/http-client-0.5.7.0) Bindings to `{{baseModule}}`
## Swagger Auto-Generated [http-client](https://www.stackage.org/lts-10.0/package/http-client-0.5.7.1) Bindings to `{{appName}}`

The library in `lib` provides auto-generated-from-Swagger [http-client](https://www.stackage.org/lts-9.0/package/http-client-0.5.7.0) bindings to the {{baseModule}} API.
The library in `lib` provides auto-generated-from-Swagger [http-client](https://www.stackage.org/lts-10.0/package/http-client-0.5.7.1) bindings to the {{appName}} API.

Targeted swagger version: {{swaggerVersion}}

Expand Down Expand Up @@ -71,7 +71,7 @@ These options allow some customization of the code generation process.
| generateFormUrlEncodedInstances | Generate FromForm/ToForm instances for models used by x-www-form-urlencoded operations (model fields must be primitive types) | true | {{{generateFormUrlEncodedInstances}}} |
| generateLenses | Generate Lens optics for Models | true | {{{generateLenses}}} |
| generateModelConstructors | Generate smart constructors (only supply required fields) for models | true | {{{generateModelConstructors}}} |
| inlineMimeTypes | Inline (hardcode) the content-type and accept parameters on operations, when there is only 1 option | false | {{{inlineMimeTypes}}} |
| inlineMimeTypes | Inline (hardcode) the content-type and accept parameters on operations, when there is only 1 option | true | {{{inlineMimeTypes}}} |
| modelDeriving | Additional classes to include in the deriving() clause of Models | | {{{modelDeriving}}} |
| requestType | Set the name of the type used to generate requests | | {{{requestType}}} |
| strictFields | Add strictness annotations to all model fields | true | {{{x-strictFields}}} |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ library
, http-client >=0.5 && <0.6
, http-client-tls
, http-media >= 0.4 && < 0.8
, http-types >=0.8 && <0.12
, http-types >=0.8 && <0.13
, iso8601-time >=0.1.3 && <0.2.0
, microlens >= 0.4.3 && <0.5
, mtl >=2.2.1
, network >=2.6.2 && <2.7
, random >=1.1
, safe-exceptions <0.2
, text >=0.11 && <1.3
, time >=1.5 && <1.9
, time >=1.5 && <1.10
, transformers >=0.4.0.0
, unordered-containers
, vector >=0.10.9 && <0.13
Expand Down
6 changes: 3 additions & 3 deletions samples/client/petstore/haskell-http-client/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Swagger Auto-Generated [http-client](https://www.stackage.org/lts-9.0/package/http-client-0.5.7.0) Bindings to `SwaggerPetstore`
## Swagger Auto-Generated [http-client](https://www.stackage.org/lts-10.0/package/http-client-0.5.7.1) Bindings to `Swagger Petstore`

The library in `lib` provides auto-generated-from-Swagger [http-client](https://www.stackage.org/lts-9.0/package/http-client-0.5.7.0) bindings to the SwaggerPetstore API.
The library in `lib` provides auto-generated-from-Swagger [http-client](https://www.stackage.org/lts-10.0/package/http-client-0.5.7.1) bindings to the Swagger Petstore API.

Targeted swagger version: 2.0

Expand Down Expand Up @@ -71,7 +71,7 @@ These options allow some customization of the code generation process.
| generateFormUrlEncodedInstances | Generate FromForm/ToForm instances for models used by x-www-form-urlencoded operations (model fields must be primitive types) | true | true |
| generateLenses | Generate Lens optics for Models | true | true |
| generateModelConstructors | Generate smart constructors (only supply required fields) for models | true | true |
| inlineMimeTypes | Inline (hardcode) the content-type and accept parameters on operations, when there is only 1 option | false | false |
| inlineMimeTypes | Inline (hardcode) the content-type and accept parameters on operations, when there is only 1 option | true | true |
| modelDeriving | Additional classes to include in the deriving() clause of Models | | |
| requestType | Set the name of the type used to generate requests | | SwaggerPetstoreRequest |
| strictFields | Add strictness annotations to all model fields | true | true |
Expand Down
Loading

0 comments on commit 2d0bafb

Please sign in to comment.