Skip to content
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

Add an option to skip "form" model generation #700

Merged
merged 7 commits into from
Aug 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ java -Dapis -DmodelTests=false {opts}

When using selective generation, _only_ the templates needed for the specific generation will be used.

To skip models defined as the form parameters in "requestBody", please use `skipFormModel` (default to false) (this option is introduced at v3.2.2)

```sh
java -DskipFormModel=true
```

This option will be helpful to skip model generation due to the form parameter, which is defined differently in OAS3 as there's no form parameter in OAS3

### Ignore file format

OpenAPI Generator supports a `.openapi-generator-ignore` file, similar to `.gitignore` or `.dockerignore` you're probably already familiar with.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class CodegenConstants {
public static final String API_TESTS = "apiTests";
public static final String API_DOCS = "apiDocs";
public static final String WITH_XML = "withXml";
public static final String SKIP_FORM_MODEL = "skipFormModel";
/* /end System Properties */

public static final String API_PACKAGE = "apiPackage";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ private void generateModelTests(List<File> files, Map<String, Object> models, St
private void generateModelDocumentation(List<File> files, Map<String, Object> models, String modelName) throws IOException {
for (String templateName : config.modelDocTemplateFiles().keySet()) {
String docExtension = config.getDocExtension();
String suffix = docExtension!=null ? docExtension : config.modelDocTemplateFiles().get(templateName);
String suffix = docExtension != null ? docExtension : config.modelDocTemplateFiles().get(templateName);
String filename = config.modelDocFileFolder() + File.separator + config.toModelDocFilename(modelName) + suffix;
if (!config.shouldOverwrite(filename)) {
LOGGER.info("Skipped overwriting " + filename);
Expand Down Expand Up @@ -382,6 +382,10 @@ private Model getParent(Model model) {
} */
});

Boolean skipFormModel = System.getProperty(CodegenConstants.SKIP_FORM_MODEL) != null ?
Boolean.valueOf(System.getProperty(CodegenConstants.SKIP_FORM_MODEL)) :
getGeneratorPropertyDefaultSwitch(CodegenConstants.SKIP_FORM_MODEL, false);

// process models only
for (String name : modelKeys) {
try {
Expand All @@ -393,8 +397,13 @@ private Model getParent(Model model) {

// don't generate models that are not used as object (e.g. form parameters)
if (unusedModels.contains(name)) {
LOGGER.debug("Model " + name + " not generated since it's marked as unused (due to form parameters)");
continue;
if (Boolean.FALSE.equals(skipFormModel)) {
// if skipFormModel sets to true, still generate the model and log the result
LOGGER.info("Model " + name + " (marked as unused due to form parameters) is generated due to skipFormModel=false (default)");
} else {
LOGGER.info("Model " + name + " not generated since it's marked as unused (due to form parameters) and skipFormModel set to true");
continue;
}
}

Schema schema = schemas.get(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ fakeOuterBooleanSerialize _ =
data FakeOuterBooleanSerialize

-- | /Body Param/ "body" - Input boolean as post body
instance HasBodyParam FakeOuterBooleanSerialize BodyBool
instance HasBodyParam FakeOuterBooleanSerialize Body8

-- | @application/json@
instance Consumes FakeOuterBooleanSerialize MimeJSON
Expand Down Expand Up @@ -123,7 +123,7 @@ fakeOuterNumberSerialize _ =
data FakeOuterNumberSerialize

-- | /Body Param/ "body" - Input number as post body
instance HasBodyParam FakeOuterNumberSerialize Body
instance HasBodyParam FakeOuterNumberSerialize Body6

-- | @application/json@
instance Consumes FakeOuterNumberSerialize MimeJSON
Expand All @@ -148,7 +148,7 @@ fakeOuterStringSerialize _ =
data FakeOuterStringSerialize

-- | /Body Param/ "body" - Input string as post body
instance HasBodyParam FakeOuterStringSerialize BodyText
instance HasBodyParam FakeOuterStringSerialize Body7

-- | @application/json@
instance Consumes FakeOuterStringSerialize MimeJSON
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ newtype AdditionalMetadata = AdditionalMetadata { unAdditionalMetadata :: Text }
-- ** ApiKey
newtype ApiKey = ApiKey { unApiKey :: Text } deriving (P.Eq, P.Show)

-- ** Body
newtype Body = Body { unBody :: Double } deriving (P.Eq, P.Show, A.ToJSON)
-- ** Body6
newtype Body6 = Body6 { unBody6 :: Double } deriving (P.Eq, P.Show, A.ToJSON)

-- ** BodyBool
newtype BodyBool = BodyBool { unBodyBool :: Bool } deriving (P.Eq, P.Show, A.ToJSON)
-- ** Body7
newtype Body7 = Body7 { unBody7 :: Text } deriving (P.Eq, P.Show, A.ToJSON)

-- ** BodyText
newtype BodyText = BodyText { unBodyText :: Text } deriving (P.Eq, P.Show, A.ToJSON)
-- ** Body8
newtype Body8 = Body8 { unBody8 :: Bool } deriving (P.Eq, P.Show, A.ToJSON)

-- ** Byte
newtype Byte = Byte { unByte :: ByteArray } deriving (P.Eq, P.Show)
Expand Down Expand Up @@ -416,6 +416,253 @@ mkArrayTest =
, arrayTestArrayArrayOfModel = Nothing
}

-- ** Body
-- | Body
data Body = Body
{ bodyName :: !(Maybe Text) -- ^ "name" - Updated name of the pet
, bodyStatus :: !(Maybe Text) -- ^ "status" - Updated status of the pet
} deriving (P.Show, P.Eq, P.Typeable)

-- | FromJSON Body
instance A.FromJSON Body where
parseJSON = A.withObject "Body" $ \o ->
Body
<$> (o .:? "name")
<*> (o .:? "status")

-- | ToJSON Body
instance A.ToJSON Body where
toJSON Body {..} =
_omitNulls
[ "name" .= bodyName
, "status" .= bodyStatus
]


-- | Construct a value of type 'Body' (by applying it's required fields, if any)
mkBody
:: Body
mkBody =
Body
{ bodyName = Nothing
, bodyStatus = Nothing
}

-- ** Body1
-- | Body1
data Body1 = Body1
{ body1AdditionalMetadata :: !(Maybe Text) -- ^ "additionalMetadata" - Additional data to pass to server
, body1File :: !(Maybe FilePath) -- ^ "file" - file to upload
} deriving (P.Show, P.Eq, P.Typeable)

-- | FromJSON Body1
instance A.FromJSON Body1 where
parseJSON = A.withObject "Body1" $ \o ->
Body1
<$> (o .:? "additionalMetadata")
<*> (o .:? "file")

-- | ToJSON Body1
instance A.ToJSON Body1 where
toJSON Body1 {..} =
_omitNulls
[ "additionalMetadata" .= body1AdditionalMetadata
, "file" .= body1File
]


-- | Construct a value of type 'Body1' (by applying it's required fields, if any)
mkBody1
:: Body1
mkBody1 =
Body1
{ body1AdditionalMetadata = Nothing
, body1File = Nothing
}

-- ** Body2
-- | Body2
data Body2 = Body2
{ body2EnumFormStringArray :: !(Maybe [E'EnumFormStringArray]) -- ^ "enum_form_string_array" - Form parameter enum test (string array)
, body2EnumFormString :: !(Maybe E'EnumFormString) -- ^ "enum_form_string" - Form parameter enum test (string)
} deriving (P.Show, P.Eq, P.Typeable)

-- | FromJSON Body2
instance A.FromJSON Body2 where
parseJSON = A.withObject "Body2" $ \o ->
Body2
<$> (o .:? "enum_form_string_array")
<*> (o .:? "enum_form_string")

-- | ToJSON Body2
instance A.ToJSON Body2 where
toJSON Body2 {..} =
_omitNulls
[ "enum_form_string_array" .= body2EnumFormStringArray
, "enum_form_string" .= body2EnumFormString
]


-- | Construct a value of type 'Body2' (by applying it's required fields, if any)
mkBody2
:: Body2
mkBody2 =
Body2
{ body2EnumFormStringArray = Nothing
, body2EnumFormString = Nothing
}

-- ** Body3
-- | Body3
data Body3 = Body3
{ body3Integer :: !(Maybe Int) -- ^ "integer" - None
, body3Int32 :: !(Maybe Int) -- ^ "int32" - None
, body3Int64 :: !(Maybe Integer) -- ^ "int64" - None
, body3Number :: !(Double) -- ^ /Required/ "number" - None
, body3Float :: !(Maybe Float) -- ^ "float" - None
, body3Double :: !(Double) -- ^ /Required/ "double" - None
, body3String :: !(Maybe Text) -- ^ "string" - None
, body3PatternWithoutDelimiter :: !(Text) -- ^ /Required/ "pattern_without_delimiter" - None
, body3Byte :: !(ByteArray) -- ^ /Required/ "byte" - None
, body3Binary :: !(Maybe FilePath) -- ^ "binary" - None
, body3Date :: !(Maybe Date) -- ^ "date" - None
, body3DateTime :: !(Maybe DateTime) -- ^ "dateTime" - None
, body3Password :: !(Maybe Text) -- ^ "password" - None
, body3Callback :: !(Maybe Text) -- ^ "callback" - None
} deriving (P.Show, P.Eq, P.Typeable)

-- | FromJSON Body3
instance A.FromJSON Body3 where
parseJSON = A.withObject "Body3" $ \o ->
Body3
<$> (o .:? "integer")
<*> (o .:? "int32")
<*> (o .:? "int64")
<*> (o .: "number")
<*> (o .:? "float")
<*> (o .: "double")
<*> (o .:? "string")
<*> (o .: "pattern_without_delimiter")
<*> (o .: "byte")
<*> (o .:? "binary")
<*> (o .:? "date")
<*> (o .:? "dateTime")
<*> (o .:? "password")
<*> (o .:? "callback")

-- | ToJSON Body3
instance A.ToJSON Body3 where
toJSON Body3 {..} =
_omitNulls
[ "integer" .= body3Integer
, "int32" .= body3Int32
, "int64" .= body3Int64
, "number" .= body3Number
, "float" .= body3Float
, "double" .= body3Double
, "string" .= body3String
, "pattern_without_delimiter" .= body3PatternWithoutDelimiter
, "byte" .= body3Byte
, "binary" .= body3Binary
, "date" .= body3Date
, "dateTime" .= body3DateTime
, "password" .= body3Password
, "callback" .= body3Callback
]


-- | Construct a value of type 'Body3' (by applying it's required fields, if any)
mkBody3
:: Double -- ^ 'body3Number': None
-> Double -- ^ 'body3Double': None
-> Text -- ^ 'body3PatternWithoutDelimiter': None
-> ByteArray -- ^ 'body3Byte': None
-> Body3
mkBody3 body3Number body3Double body3PatternWithoutDelimiter body3Byte =
Body3
{ body3Integer = Nothing
, body3Int32 = Nothing
, body3Int64 = Nothing
, body3Number
, body3Float = Nothing
, body3Double
, body3String = Nothing
, body3PatternWithoutDelimiter
, body3Byte
, body3Binary = Nothing
, body3Date = Nothing
, body3DateTime = Nothing
, body3Password = Nothing
, body3Callback = Nothing
}

-- ** Body4
-- | Body4
data Body4 = Body4
{ body4Param :: !(Text) -- ^ /Required/ "param" - field1
, body4Param2 :: !(Text) -- ^ /Required/ "param2" - field2
} deriving (P.Show, P.Eq, P.Typeable)

-- | FromJSON Body4
instance A.FromJSON Body4 where
parseJSON = A.withObject "Body4" $ \o ->
Body4
<$> (o .: "param")
<*> (o .: "param2")

-- | ToJSON Body4
instance A.ToJSON Body4 where
toJSON Body4 {..} =
_omitNulls
[ "param" .= body4Param
, "param2" .= body4Param2
]


-- | Construct a value of type 'Body4' (by applying it's required fields, if any)
mkBody4
:: Text -- ^ 'body4Param': field1
-> Text -- ^ 'body4Param2': field2
-> Body4
mkBody4 body4Param body4Param2 =
Body4
{ body4Param
, body4Param2
}

-- ** Body5
-- | Body5
data Body5 = Body5
{ body5AdditionalMetadata :: !(Maybe Text) -- ^ "additionalMetadata" - Additional data to pass to server
, body5RequiredFile :: !(FilePath) -- ^ /Required/ "requiredFile" - file to upload
} deriving (P.Show, P.Eq, P.Typeable)

-- | FromJSON Body5
instance A.FromJSON Body5 where
parseJSON = A.withObject "Body5" $ \o ->
Body5
<$> (o .:? "additionalMetadata")
<*> (o .: "requiredFile")

-- | ToJSON Body5
instance A.ToJSON Body5 where
toJSON Body5 {..} =
_omitNulls
[ "additionalMetadata" .= body5AdditionalMetadata
, "requiredFile" .= body5RequiredFile
]


-- | Construct a value of type 'Body5' (by applying it's required fields, if any)
mkBody5
:: FilePath -- ^ 'body5RequiredFile': file to upload
-> Body5
mkBody5 body5RequiredFile =
Body5
{ body5AdditionalMetadata = Nothing
, body5RequiredFile
}

-- ** Capitalization
-- | Capitalization
data Capitalization = Capitalization
Expand Down
Loading