Skip to content

Commit

Permalink
Merge pull request #9932 from swagger-api/model_class_option
Browse files Browse the repository at this point in the history
added option to use classes as models
  • Loading branch information
HugoMario authored Dec 12, 2019
2 parents a408204 + 740820a commit b22ed93
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public class Swift4Codegen extends DefaultCodegen implements CodegenConfig {
protected static final String LIBRARY_PROMISE_KIT = "PromiseKit";
protected static final String LIBRARY_RX_SWIFT = "RxSwift";
protected static final String[] RESPONSE_LIBRARIES = {LIBRARY_PROMISE_KIT, LIBRARY_RX_SWIFT};
protected static final String MODEL_CLASSES = "modelClasses";
protected String projectName = "SwaggerClient";
protected boolean unwrapRequired;
protected boolean objcCompatible = false;
Expand Down Expand Up @@ -302,6 +303,10 @@ public void processOpts() {
additionalProperties.put(POD_AUTHORS, DEFAULT_POD_AUTHORS);
}

if (additionalProperties.containsKey(MODEL_CLASSES)) {
additionalProperties.put("useModelClasses", true);
}

setLenientTypeCast(convertPropertyToBooleanAndWriteBack(LENIENT_TYPE_CAST));

supportingFiles.add(new SupportingFile("Podspec.mustache",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class Swift5Codegen extends DefaultCodegen implements CodegenConfig {
private static final String LIBRARY_PROMISE_KIT = "PromiseKit";
private static final String LIBRARY_RX_SWIFT = "RxSwift";
private static final String[] RESPONSE_LIBRARIES = {LIBRARY_PROMISE_KIT, LIBRARY_RX_SWIFT};
protected static final String MODEL_CLASSES = "modelClasses";
protected String projectName = "SwaggerClient";
private boolean unwrapRequired;
private boolean objcCompatible = false;
Expand Down Expand Up @@ -289,6 +290,10 @@ public void processOpts() {
additionalProperties.put(POD_AUTHORS, DEFAULT_POD_AUTHORS);
}

if (additionalProperties.containsKey(MODEL_CLASSES)) {
additionalProperties.put("useModelClasses", true);
}

setLenientTypeCast(convertPropertyToBooleanAndWriteBack(LENIENT_TYPE_CAST));

supportingFiles.add(new SupportingFile("Podspec.mustache",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

public struct {{classname}}: Codable {
public {{#useModelClasses}}class{{/useModelClasses}}{{^useModelClasses}}struct{{/useModelClasses}} {{classname}}: Codable {
{{#allVars}}
{{#isEnum}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

public struct {{classname}}: Codable {
public {{#useModelClasses}}class{{/useModelClasses}}{{^useModelClasses}}struct{{/useModelClasses}} {{classname}}: Codable {
{{#allVars}}
{{#isEnum}}
Expand Down

0 comments on commit b22ed93

Please sign in to comment.