Merge remote-tracking branch 'origin/develop' into develop
This commit is contained in:
@@ -1,20 +1,17 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Copyright 2015 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.github.robwin.swagger2markup;
|
||||
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.github.robwin.swagger2markup;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
@@ -1,20 +1,17 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Copyright 2015 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.github.robwin.swagger2markup;
|
||||
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.github.robwin.swagger2markup;
|
||||
|
||||
import io.swagger.models.HttpMethod;
|
||||
|
||||
@@ -1,20 +1,17 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Copyright 2015 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.github.robwin.swagger2markup;
|
||||
|
||||
@@ -194,20 +191,6 @@ public class Swagger2MarkupConverter {
|
||||
this.swagger = readSwagger(swaggerUrl.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Uses the SwaggerParser to read the Swagger source.
|
||||
*
|
||||
* @param swaggerLocation the location of the Swagger source
|
||||
* @return the Swagger model
|
||||
*/
|
||||
private Swagger readSwagger(String swaggerLocation){
|
||||
Swagger swagger = new SwaggerParser().read(swaggerLocation);
|
||||
if (swagger == null) {
|
||||
throw new IllegalArgumentException("Failed to read the Swagger source");
|
||||
}
|
||||
return swagger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Builder from a local Path.
|
||||
*
|
||||
@@ -228,12 +211,28 @@ public class Swagger2MarkupConverter {
|
||||
this.swaggerLocation = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Uses the SwaggerParser to read the Swagger source.
|
||||
*
|
||||
* @param swaggerLocation the location of the Swagger source
|
||||
* @return the Swagger model
|
||||
*/
|
||||
private Swagger readSwagger(String swaggerLocation){
|
||||
Swagger swagger = new SwaggerParser().read(swaggerLocation);
|
||||
if (swagger == null) {
|
||||
throw new IllegalArgumentException("Failed to read the Swagger source");
|
||||
}
|
||||
return swagger;
|
||||
}
|
||||
|
||||
public Builder withConfig(Swagger2MarkupConfig config) {
|
||||
Validate.notNull(config, "config must not be null");
|
||||
this.config = config;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withExtensionRegistry(Swagger2MarkupExtensionRegistry registry) {
|
||||
Validate.notNull(config, "registry must not be null");
|
||||
this.extensionRegistry = registry;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -1,20 +1,17 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Copyright 2015 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.github.robwin.swagger2markup.builder.document;
|
||||
|
||||
@@ -119,9 +116,9 @@ public class DefinitionsDocument extends MarkupDocument {
|
||||
private void definitions(Map<String, Model> definitions) {
|
||||
if (MapUtils.isNotEmpty(definitions)) {
|
||||
|
||||
applyDefinitionExtension(new DefinitionsContentExtension.Context(DefinitionsContentExtension.Position.DOC_BEFORE, this.markupDocBuilder, null));
|
||||
applyDefinitionExtension(new DefinitionsContentExtension.Context(DefinitionsContentExtension.Position.DOC_BEFORE, this.markupDocBuilder));
|
||||
addDefinitionsTitle(DEFINITIONS);
|
||||
applyDefinitionExtension(new DefinitionsContentExtension.Context(DefinitionsContentExtension.Position.DOC_BEGIN, this.markupDocBuilder, null));
|
||||
applyDefinitionExtension(new DefinitionsContentExtension.Context(DefinitionsContentExtension.Position.DOC_BEGIN, this.markupDocBuilder));
|
||||
|
||||
Set<String> definitionNames;
|
||||
if (config.getDefinitionOrdering() == null)
|
||||
@@ -145,8 +142,8 @@ public class DefinitionsDocument extends MarkupDocument {
|
||||
}
|
||||
}
|
||||
|
||||
applyDefinitionExtension(new DefinitionsContentExtension.Context(DefinitionsContentExtension.Position.DOC_END, this.markupDocBuilder, null));
|
||||
applyDefinitionExtension(new DefinitionsContentExtension.Context(DefinitionsContentExtension.Position.DOC_AFTER, this.markupDocBuilder, null));
|
||||
applyDefinitionExtension(new DefinitionsContentExtension.Context(DefinitionsContentExtension.Position.DOC_END, this.markupDocBuilder));
|
||||
applyDefinitionExtension(new DefinitionsContentExtension.Context(DefinitionsContentExtension.Position.DOC_AFTER, this.markupDocBuilder));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -305,8 +302,7 @@ public class DefinitionsDocument extends MarkupDocument {
|
||||
return definitions.containsKey(ref)
|
||||
? getAllProperties(definitions, definitions.get(ref))
|
||||
: null;
|
||||
}
|
||||
if (model instanceof ComposedModel) {
|
||||
} else if (model instanceof ComposedModel) {
|
||||
ComposedModel composedModel = (ComposedModel) model;
|
||||
Map<String, Property> allProperties = new HashMap<>();
|
||||
if (composedModel.getAllOf() != null) {
|
||||
|
||||
@@ -1,20 +1,17 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Copyright 2015 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.github.robwin.swagger2markup.builder.document;
|
||||
|
||||
|
||||
@@ -1,20 +1,17 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Copyright 2015 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.github.robwin.swagger2markup.builder.document;
|
||||
|
||||
|
||||
@@ -1,20 +1,17 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Copyright 2015 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.github.robwin.swagger2markup.builder.document;
|
||||
|
||||
@@ -102,7 +99,7 @@ public class PathsDocument extends MarkupDocument {
|
||||
DEPRECATED_OPERATION = labels.getString("operation.deprecated");
|
||||
UNKNOWN = labels.getString("unknown");
|
||||
|
||||
if (config.isExamplesEnabled()) {
|
||||
if (config.isGeneratedExamplesEnabled()) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Include examples is enabled.");
|
||||
}
|
||||
@@ -169,13 +166,13 @@ public class PathsDocument extends MarkupDocument {
|
||||
|
||||
if (allOperations.size() > 0) {
|
||||
|
||||
applyOperationExtension(new OperationsContentExtension.Context(OperationsContentExtension.Position.DOC_BEFORE, this.markupDocBuilder, null));
|
||||
applyOperationExtension(new OperationsContentExtension.Context(OperationsContentExtension.Position.DOC_BEFORE, this.markupDocBuilder));
|
||||
if (config.getOperationsGroupedBy() == GroupBy.AS_IS) {
|
||||
addPathsTitle(PATHS);
|
||||
applyOperationExtension(new OperationsContentExtension.Context(OperationsContentExtension.Position.DOC_BEGIN, this.markupDocBuilder, null));
|
||||
applyOperationExtension(new OperationsContentExtension.Context(OperationsContentExtension.Position.DOC_BEGIN, this.markupDocBuilder));
|
||||
} else {
|
||||
addPathsTitle(RESOURCES);
|
||||
applyOperationExtension(new OperationsContentExtension.Context(OperationsContentExtension.Position.DOC_BEGIN, this.markupDocBuilder, null));
|
||||
applyOperationExtension(new OperationsContentExtension.Context(OperationsContentExtension.Position.DOC_BEGIN, this.markupDocBuilder));
|
||||
}
|
||||
|
||||
if (config.getOperationsGroupedBy() == GroupBy.AS_IS) {
|
||||
@@ -206,8 +203,8 @@ public class PathsDocument extends MarkupDocument {
|
||||
}
|
||||
}
|
||||
|
||||
applyOperationExtension(new OperationsContentExtension.Context(OperationsContentExtension.Position.DOC_END, this.markupDocBuilder, null));
|
||||
applyOperationExtension(new OperationsContentExtension.Context(OperationsContentExtension.Position.DOC_AFTER, this.markupDocBuilder, null));
|
||||
applyOperationExtension(new OperationsContentExtension.Context(OperationsContentExtension.Position.DOC_END, this.markupDocBuilder));
|
||||
applyOperationExtension(new OperationsContentExtension.Context(OperationsContentExtension.Position.DOC_AFTER, this.markupDocBuilder));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -593,26 +590,19 @@ public class PathsDocument extends MarkupDocument {
|
||||
*/
|
||||
private void examplesSection(PathOperation operation, MarkupDocBuilder docBuilder) {
|
||||
|
||||
if (globalContext.config.isExamplesEnabled()) {
|
||||
Optional<Map<String, Object>> generatedRequestExampleMap;
|
||||
Optional<Map<String, Object>> generatedResponseExampleMap;
|
||||
Map<String, Object> generatedRequestExampleMap = ExamplesUtil.generateRequestExampleMap(globalContext.config.isGeneratedExamplesEnabled(), operation, globalContext.swagger.getDefinitions(), markupDocBuilder);
|
||||
Map<String, Object> generatedResponseExampleMap = ExamplesUtil.generateResponseExampleMap(globalContext.config.isGeneratedExamplesEnabled(), operation.getOperation(), globalContext.swagger.getDefinitions(), markupDocBuilder);
|
||||
|
||||
generatedRequestExampleMap = ExamplesUtil.generateRequestExampleMap(operation, globalContext.swagger.getDefinitions(), markupDocBuilder);
|
||||
generatedResponseExampleMap = ExamplesUtil.generateResponseExampleMap(operation.getOperation(), globalContext.swagger.getDefinitions(), markupDocBuilder);
|
||||
|
||||
exampleMap(generatedRequestExampleMap, EXAMPLE_REQUEST, REQUEST, docBuilder);
|
||||
exampleMap(generatedResponseExampleMap, EXAMPLE_RESPONSE, RESPONSE, docBuilder);
|
||||
}
|
||||
exampleMap(generatedRequestExampleMap, EXAMPLE_REQUEST, REQUEST, docBuilder);
|
||||
exampleMap(generatedResponseExampleMap, EXAMPLE_RESPONSE, RESPONSE, docBuilder);
|
||||
}
|
||||
|
||||
private void exampleMap(Optional<Map<String, Object>> exampleMap, String operationSectionTitle, String sectionTile, MarkupDocBuilder docBuilder){
|
||||
if (exampleMap.isPresent()) {
|
||||
private void exampleMap(Map<String, Object> exampleMap, String operationSectionTitle, String sectionTile, MarkupDocBuilder docBuilder) {
|
||||
if (exampleMap.size() > 0) {
|
||||
addOperationSectionTitle(operationSectionTitle, docBuilder);
|
||||
if (exampleMap.get().size() > 0) {
|
||||
for (Map.Entry<String, Object> entry : exampleMap.get().entrySet()) {
|
||||
docBuilder.sectionTitleLevel4(sectionTile + " " + entry.getKey() + " :");
|
||||
docBuilder.listing(Json.pretty(entry.getValue()));
|
||||
}
|
||||
for (Map.Entry<String, Object> entry : exampleMap.entrySet()) {
|
||||
addOperationSectionTitle(sectionTile + " " + entry.getKey(), docBuilder);
|
||||
docBuilder.listing(Json.pretty(entry.getValue()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +1,17 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Copyright 2015 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.github.robwin.swagger2markup.builder.document;
|
||||
|
||||
|
||||
@@ -1,20 +1,17 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Copyright 2015 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.github.robwin.swagger2markup.config;
|
||||
|
||||
@@ -41,7 +38,7 @@ public class Swagger2MarkupConfig {
|
||||
private static final Logger logger = LoggerFactory.getLogger(Swagger2MarkupConfig.class);
|
||||
|
||||
private MarkupLanguage markupLanguage;
|
||||
private boolean examplesEnabled;
|
||||
private boolean generatedExamplesEnabled;
|
||||
private boolean schemasEnabled;
|
||||
private URI schemasUri;
|
||||
private boolean operationDescriptionsEnabled;
|
||||
@@ -142,8 +139,8 @@ public class Swagger2MarkupConfig {
|
||||
return markupLanguage;
|
||||
}
|
||||
|
||||
public boolean isExamplesEnabled() {
|
||||
return examplesEnabled;
|
||||
public boolean isGeneratedExamplesEnabled() {
|
||||
return generatedExamplesEnabled;
|
||||
}
|
||||
|
||||
public boolean isSchemasEnabled() {
|
||||
@@ -327,7 +324,7 @@ public class Swagger2MarkupConfig {
|
||||
safeProperties.putAll(properties);
|
||||
|
||||
config.markupLanguage = MarkupLanguage.valueOf(safeProperties.getProperty(PROPERTIES_PREFIX + "markupLanguage"));
|
||||
config.examplesEnabled = Boolean.valueOf(safeProperties.getProperty(PROPERTIES_PREFIX + "examplesEnabled"));
|
||||
config.generatedExamplesEnabled = Boolean.valueOf(safeProperties.getProperty(PROPERTIES_PREFIX + "generatedExamplesEnabled"));
|
||||
config.schemasEnabled = Boolean.valueOf(safeProperties.getProperty(PROPERTIES_PREFIX + "schemasEnabled"));
|
||||
if (safeProperties.containsKey(PROPERTIES_PREFIX + "schemasUri"))
|
||||
config.schemasUri = URI.create(safeProperties.getProperty(PROPERTIES_PREFIX + "schemasUri"));
|
||||
@@ -402,27 +399,29 @@ public class Swagger2MarkupConfig {
|
||||
* @return this builder
|
||||
*/
|
||||
public Builder withMarkupLanguage(MarkupLanguage markupLanguage) {
|
||||
Validate.notNull(markupLanguage, "%s must not be null", "markupLanguage");
|
||||
config.markupLanguage = markupLanguage;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Include examples into the Paths document
|
||||
* Include generated examples into the Paths document
|
||||
*
|
||||
* @return this builder
|
||||
*/
|
||||
public Builder withExamples() {
|
||||
config.examplesEnabled = true;
|
||||
public Builder withGeneratedExamples() {
|
||||
config.generatedExamplesEnabled = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Include (JSON, XML) schemas into the Definitions document
|
||||
*
|
||||
* @param schemasUri the URI to the folder where the schema documents reside. Use default URI if null.
|
||||
* @param schemasUri the URI to the folder where the schema documents reside.
|
||||
* @return this builder
|
||||
*/
|
||||
public Builder withSchemas(URI schemasUri) {
|
||||
Validate.notNull(schemasUri, "%s must not be null", "schemasUri");
|
||||
config.schemasEnabled = true;
|
||||
config.schemasUri = schemasUri;
|
||||
return this;
|
||||
@@ -435,6 +434,7 @@ public class Swagger2MarkupConfig {
|
||||
* @return this builder
|
||||
*/
|
||||
public Builder withSchemas(Path schemasPath) {
|
||||
Validate.notNull(schemasPath, "%s must not be null", "schemasPath");
|
||||
return withSchemas(schemasPath.toUri());
|
||||
}
|
||||
|
||||
@@ -445,7 +445,7 @@ public class Swagger2MarkupConfig {
|
||||
* @return this builder
|
||||
*/
|
||||
public Builder withSchemas() {
|
||||
withSchemas((URI) null);
|
||||
config.schemasEnabled = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -456,6 +456,7 @@ public class Swagger2MarkupConfig {
|
||||
* @return this builder
|
||||
*/
|
||||
public Builder withOperationDescriptions(URI operationDescriptionsUri) {
|
||||
Validate.notNull(operationDescriptionsUri, "%s must not be null", "operationDescriptionsUri");
|
||||
config.operationDescriptionsEnabled = true;
|
||||
config.operationDescriptionsUri = operationDescriptionsUri;
|
||||
return this;
|
||||
@@ -468,6 +469,7 @@ public class Swagger2MarkupConfig {
|
||||
* @return this builder
|
||||
*/
|
||||
public Builder withOperationDescriptions(Path operationDescriptionsPath) {
|
||||
Validate.notNull(operationDescriptionsPath, "%s must not be null", "operationDescriptionsPath");
|
||||
return withOperationDescriptions(operationDescriptionsPath.toUri());
|
||||
}
|
||||
|
||||
@@ -478,7 +480,7 @@ public class Swagger2MarkupConfig {
|
||||
* @return this builder
|
||||
*/
|
||||
public Builder withOperationDescriptions() {
|
||||
withOperationDescriptions((URI) null);
|
||||
config.operationDescriptionsEnabled = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -489,6 +491,7 @@ public class Swagger2MarkupConfig {
|
||||
* @return this builder
|
||||
*/
|
||||
public Builder withDefinitionDescriptions(URI definitionDescriptionsUri) {
|
||||
Validate.notNull(definitionDescriptionsUri, "%s must not be null", "definitionDescriptionsUri");
|
||||
config.definitionDescriptionsEnabled = true;
|
||||
config.definitionDescriptionsUri = definitionDescriptionsUri;
|
||||
return this;
|
||||
@@ -501,6 +504,7 @@ public class Swagger2MarkupConfig {
|
||||
* @return this builder
|
||||
*/
|
||||
public Builder withDefinitionDescriptions(Path definitionDescriptionsPath) {
|
||||
Validate.notNull(definitionDescriptionsPath, "%s must not be null", "definitionDescriptionsPath");
|
||||
return withDefinitionDescriptions(definitionDescriptionsPath.toUri());
|
||||
}
|
||||
|
||||
@@ -511,7 +515,7 @@ public class Swagger2MarkupConfig {
|
||||
* @return this builder
|
||||
*/
|
||||
public Builder withDefinitionDescriptions() {
|
||||
withDefinitionDescriptions((URI) null);
|
||||
config.definitionDescriptionsEnabled = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -544,6 +548,7 @@ public class Swagger2MarkupConfig {
|
||||
* @return this builder
|
||||
*/
|
||||
public Builder withPathsGroupedBy(GroupBy pathsGroupedBy) {
|
||||
Validate.notNull(pathsGroupedBy, "%s must not be null", "pathsGroupedBy");
|
||||
config.operationsGroupedBy = pathsGroupedBy;
|
||||
return this;
|
||||
}
|
||||
@@ -555,6 +560,7 @@ public class Swagger2MarkupConfig {
|
||||
* @return this builder
|
||||
*/
|
||||
public Builder withOutputLanguage(Language language) {
|
||||
Validate.notNull(language, "%s must not be null", "language");
|
||||
config.outputLanguage = language;
|
||||
return this;
|
||||
}
|
||||
@@ -566,6 +572,7 @@ public class Swagger2MarkupConfig {
|
||||
* @return this builder
|
||||
*/
|
||||
public Builder withInlineSchemaDepthLevel(int inlineSchemaDepthLevel) {
|
||||
Validate.notNull(inlineSchemaDepthLevel, "%s must not be null", "inlineSchemaDepthLevel");
|
||||
config.inlineSchemaDepthLevel = inlineSchemaDepthLevel;
|
||||
return this;
|
||||
}
|
||||
@@ -579,6 +586,7 @@ public class Swagger2MarkupConfig {
|
||||
* @return this builder
|
||||
*/
|
||||
public Builder withTagOrdering(OrderBy orderBy) {
|
||||
Validate.notNull(orderBy, "%s must not be null", "orderBy");
|
||||
Validate.isTrue(orderBy != OrderBy.CUSTOM, "You must provide a custom comparator if orderBy == OrderBy.CUSTOM");
|
||||
config.tagOrderBy = orderBy;
|
||||
return this;
|
||||
@@ -591,8 +599,7 @@ public class Swagger2MarkupConfig {
|
||||
* @return this builder
|
||||
*/
|
||||
public Builder withTagOrdering(Comparator<String> tagOrdering) {
|
||||
Validate.notNull(tagOrdering);
|
||||
|
||||
Validate.notNull(tagOrdering, "%s must not be null", "tagOrdering");
|
||||
config.tagOrderBy = OrderBy.CUSTOM;
|
||||
config.tagOrdering = tagOrdering;
|
||||
return this;
|
||||
@@ -607,6 +614,7 @@ public class Swagger2MarkupConfig {
|
||||
* @return this builder
|
||||
*/
|
||||
public Builder withOperationOrdering(OrderBy orderBy) {
|
||||
Validate.notNull(orderBy, "%s must not be null", "orderBy");
|
||||
Validate.isTrue(orderBy != OrderBy.CUSTOM, "You must provide a custom comparator if orderBy == OrderBy.CUSTOM");
|
||||
config.operationOrderBy = orderBy;
|
||||
return this;
|
||||
@@ -619,8 +627,7 @@ public class Swagger2MarkupConfig {
|
||||
* @return this builder
|
||||
*/
|
||||
public Builder withOperationOrdering(Comparator<PathOperation> operationOrdering) {
|
||||
Validate.notNull(operationOrdering);
|
||||
|
||||
Validate.notNull(operationOrdering, "%s must not be null", "operationOrdering");
|
||||
config.operationOrderBy = OrderBy.CUSTOM;
|
||||
config.operationOrdering = operationOrdering;
|
||||
return this;
|
||||
@@ -635,6 +642,7 @@ public class Swagger2MarkupConfig {
|
||||
* @return this builder
|
||||
*/
|
||||
public Builder withDefinitionOrdering(OrderBy orderBy) {
|
||||
Validate.notNull(orderBy, "%s must not be null", "orderBy");
|
||||
Validate.isTrue(orderBy != OrderBy.CUSTOM, "You must provide a custom comparator if orderBy == OrderBy.CUSTOM");
|
||||
config.definitionOrderBy = orderBy;
|
||||
return this;
|
||||
@@ -647,8 +655,7 @@ public class Swagger2MarkupConfig {
|
||||
* @return this builder
|
||||
*/
|
||||
public Builder withDefinitionOrdering(Comparator<String> definitionOrdering) {
|
||||
Validate.notNull(definitionOrdering);
|
||||
|
||||
Validate.notNull(definitionOrdering, "%s must not be null", "definitionOrdering");
|
||||
config.definitionOrderBy = OrderBy.CUSTOM;
|
||||
config.definitionOrdering = definitionOrdering;
|
||||
return this;
|
||||
@@ -663,6 +670,7 @@ public class Swagger2MarkupConfig {
|
||||
* @return this builder
|
||||
*/
|
||||
public Builder withParameterOrdering(OrderBy orderBy) {
|
||||
Validate.notNull(orderBy, "%s must not be null", "orderBy");
|
||||
Validate.isTrue(orderBy != OrderBy.CUSTOM, "You must provide a custom comparator if orderBy == OrderBy.CUSTOM");
|
||||
config.parameterOrderBy = orderBy;
|
||||
return this;
|
||||
@@ -675,7 +683,7 @@ public class Swagger2MarkupConfig {
|
||||
* @return this builder
|
||||
*/
|
||||
public Builder withParameterOrdering(Comparator<Parameter> parameterOrdering) {
|
||||
Validate.notNull(parameterOrdering);
|
||||
Validate.notNull(parameterOrdering, "%s must not be null", "parameterOrdering");
|
||||
|
||||
config.parameterOrderBy = OrderBy.CUSTOM;
|
||||
config.parameterOrdering = parameterOrdering;
|
||||
@@ -691,6 +699,7 @@ public class Swagger2MarkupConfig {
|
||||
* @return this builder
|
||||
*/
|
||||
public Builder withPropertyOrdering(OrderBy orderBy) {
|
||||
Validate.notNull(orderBy, "%s must not be null", "orderBy");
|
||||
Validate.isTrue(orderBy != OrderBy.CUSTOM, "You must provide a custom comparator if orderBy == OrderBy.CUSTOM");
|
||||
config.propertyOrderBy = orderBy;
|
||||
return this;
|
||||
@@ -703,7 +712,7 @@ public class Swagger2MarkupConfig {
|
||||
* @return this builder
|
||||
*/
|
||||
public Builder withPropertyOrdering(Comparator<String> propertyOrdering) {
|
||||
Validate.notNull(propertyOrdering);
|
||||
Validate.notNull(propertyOrdering, "%s must not be null", "propertyOrdering");
|
||||
|
||||
config.propertyOrderBy = OrderBy.CUSTOM;
|
||||
config.propertyOrdering = propertyOrdering;
|
||||
@@ -719,6 +728,7 @@ public class Swagger2MarkupConfig {
|
||||
* @return this builder
|
||||
*/
|
||||
public Builder withResponseOrdering(OrderBy orderBy) {
|
||||
Validate.notNull(orderBy, "%s must not be null", "orderBy");
|
||||
Validate.isTrue(orderBy != OrderBy.CUSTOM, "You must provide a custom comparator if orderBy == OrderBy.CUSTOM");
|
||||
config.responseOrderBy = orderBy;
|
||||
return this;
|
||||
@@ -731,7 +741,7 @@ public class Swagger2MarkupConfig {
|
||||
* @return this builder
|
||||
*/
|
||||
public Builder withResponseOrdering(Comparator<String> responseOrdering) {
|
||||
Validate.notNull(responseOrdering);
|
||||
Validate.notNull(responseOrdering, "%s must not be null", "responseOrdering");
|
||||
|
||||
config.responseOrderBy = OrderBy.CUSTOM;
|
||||
config.responseOrdering = responseOrdering;
|
||||
@@ -745,6 +755,7 @@ public class Swagger2MarkupConfig {
|
||||
* @return this builder
|
||||
*/
|
||||
public Builder withInterDocumentCrossReferences(String prefix) {
|
||||
Validate.notNull(prefix, "%s must not be null", "prefix");
|
||||
config.interDocumentCrossReferencesEnabled = true;
|
||||
config.interDocumentCrossReferencesPrefix = prefix;
|
||||
return this;
|
||||
@@ -778,6 +789,7 @@ public class Swagger2MarkupConfig {
|
||||
* @return this builder
|
||||
*/
|
||||
public Builder withAnchorPrefix(String anchorPrefix) {
|
||||
Validate.notNull(anchorPrefix, "%s must no be null", "anchorPrefix");
|
||||
config.anchorPrefix = anchorPrefix;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.github.robwin.swagger2markup.extension;
|
||||
|
||||
import io.github.robwin.swagger2markup.Swagger2MarkupConverter;
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.github.robwin.swagger2markup.extension;
|
||||
|
||||
import io.github.robwin.markup.builder.MarkupDocBuilder;
|
||||
|
||||
@@ -1,6 +1,23 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.github.robwin.swagger2markup.extension;
|
||||
|
||||
import io.github.robwin.markup.builder.MarkupDocBuilder;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
public abstract class DefinitionsContentExtension extends AbstractExtension {
|
||||
|
||||
@@ -10,7 +27,7 @@ public abstract class DefinitionsContentExtension extends AbstractExtension {
|
||||
DOC_BEGIN,
|
||||
DOC_END,
|
||||
DEF_BEGIN,
|
||||
DEF_END;
|
||||
DEF_END
|
||||
}
|
||||
|
||||
public static class Context extends ContentContext {
|
||||
@@ -20,11 +37,19 @@ public abstract class DefinitionsContentExtension extends AbstractExtension {
|
||||
*/
|
||||
public String definitionName;
|
||||
|
||||
public Context(Position position, MarkupDocBuilder docBuilder) {
|
||||
super(docBuilder);
|
||||
Validate.isTrue(position != Position.DEF_BEGIN && position != Position.DEF_END, "You must provide a definitionName for this position");
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
public Context(Position position, MarkupDocBuilder docBuilder, String definitionName) {
|
||||
super(docBuilder);
|
||||
Validate.notNull(definitionName);
|
||||
this.position = position;
|
||||
this.definitionName = definitionName;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public DefinitionsContentExtension() {
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.github.robwin.swagger2markup.extension;
|
||||
|
||||
import io.github.robwin.swagger2markup.Swagger2MarkupConverter;
|
||||
|
||||
@@ -1,8 +1,25 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.github.robwin.swagger2markup.extension;
|
||||
|
||||
import io.github.robwin.markup.builder.MarkupDocBuilder;
|
||||
import io.github.robwin.swagger2markup.GroupBy;
|
||||
import io.github.robwin.swagger2markup.PathOperation;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
public abstract class OperationsContentExtension extends AbstractExtension {
|
||||
|
||||
@@ -22,8 +39,15 @@ public abstract class OperationsContentExtension extends AbstractExtension {
|
||||
*/
|
||||
public PathOperation operation;
|
||||
|
||||
public Context(Position position, MarkupDocBuilder docBuilder) {
|
||||
super(docBuilder);
|
||||
Validate.isTrue(position != Position.OP_BEGIN && position != Position.OP_END, "You must provide an operation for this position");
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
public Context(Position position, MarkupDocBuilder docBuilder, PathOperation operation) {
|
||||
super(docBuilder);
|
||||
Validate.notNull(operation);
|
||||
this.position = position;
|
||||
this.operation = operation;
|
||||
}
|
||||
@@ -36,6 +60,7 @@ public abstract class OperationsContentExtension extends AbstractExtension {
|
||||
|
||||
/**
|
||||
* Returns title level offset from 1 to apply to content
|
||||
*
|
||||
* @param context context
|
||||
* @return title level offset
|
||||
*/
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.github.robwin.swagger2markup.extension;
|
||||
|
||||
import io.github.robwin.markup.builder.MarkupDocBuilder;
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.github.robwin.swagger2markup.extension;
|
||||
|
||||
import io.github.robwin.markup.builder.MarkupDocBuilder;
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.github.robwin.swagger2markup.extension;
|
||||
|
||||
import com.google.common.collect.Multimap;
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.github.robwin.swagger2markup.extension;
|
||||
|
||||
import io.github.robwin.swagger2markup.Swagger2MarkupConverter;
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.github.robwin.swagger2markup.extension.repository;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.github.robwin.swagger2markup.extension.repository;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.github.robwin.swagger2markup.extension.repository;
|
||||
|
||||
import io.github.robwin.swagger2markup.Swagger2MarkupConverter;
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.github.robwin.swagger2markup.extension.repository;
|
||||
|
||||
import io.github.robwin.swagger2markup.Swagger2MarkupConverter;
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.github.robwin.swagger2markup.extension.repository;
|
||||
|
||||
import io.github.robwin.swagger2markup.Swagger2MarkupConverter;
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.github.robwin.swagger2markup.extension.repository;
|
||||
|
||||
import io.github.robwin.swagger2markup.Swagger2MarkupConverter;
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.github.robwin.swagger2markup.extension.repository;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.github.robwin.swagger2markup.type;
|
||||
|
||||
import io.github.robwin.markup.builder.MarkupDocBuilder;
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.github.robwin.swagger2markup.type;
|
||||
|
||||
import io.github.robwin.markup.builder.MarkupDocBuilder;
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.github.robwin.swagger2markup.type;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.github.robwin.swagger2markup.type;
|
||||
|
||||
import io.github.robwin.markup.builder.MarkupDocBuilder;
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.github.robwin.swagger2markup.type;
|
||||
|
||||
import io.github.robwin.markup.builder.MarkupDocBuilder;
|
||||
|
||||
@@ -1,7 +1,22 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.github.robwin.swagger2markup.type;
|
||||
|
||||
import io.github.robwin.markup.builder.MarkupDocBuilder;
|
||||
import io.github.robwin.markup.builder.MarkupDocBuilders;
|
||||
|
||||
/**
|
||||
* Reference to a type defined elsewhere
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.github.robwin.swagger2markup.type;
|
||||
|
||||
import io.github.robwin.markup.builder.MarkupDocBuilder;
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.github.robwin.swagger2markup.utils;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,21 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.github.robwin.swagger2markup.utils;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import io.github.robwin.markup.builder.MarkupDocBuilder;
|
||||
import io.github.robwin.swagger2markup.PathOperation;
|
||||
import io.swagger.models.*;
|
||||
@@ -13,6 +28,7 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -26,32 +42,33 @@ public class ExamplesUtil {
|
||||
* @param operation the Swagger Operation
|
||||
* @return map containing response examples.
|
||||
*/
|
||||
public static Optional<Map<String, Object>> generateResponseExampleMap(Operation operation, Map<String, Model> definitions, MarkupDocBuilder markupDocBuilder) {
|
||||
public static Map<String, Object> generateResponseExampleMap(boolean generateMissingExamples, Operation operation, Map<String, Model> definitions, MarkupDocBuilder markupDocBuilder) {
|
||||
Map<String, Object> examples = new HashMap<>();
|
||||
Map<String, Response> responses = operation.getResponses();
|
||||
for (Map.Entry<String, Response> responseEntry : responses.entrySet()) {
|
||||
Response response = responseEntry.getValue();
|
||||
Object example = response.getExamples();
|
||||
if (example != null) {
|
||||
examples.put(responseEntry.getKey(), example);
|
||||
} else {
|
||||
if (example == null) {
|
||||
Property schema = response.getSchema();
|
||||
example = schema != null ? schema.getExample() : null;
|
||||
if (example == null && schema instanceof RefProperty) {
|
||||
String simpleRef = ((RefProperty) schema).getSimpleRef();
|
||||
example = generateExampleForRefModel(simpleRef, definitions, markupDocBuilder);
|
||||
}
|
||||
if (example == null && schema != null) {
|
||||
examples.put(responseEntry.getKey(), PropertyUtils.exampleFromType(schema.getType(), schema, markupDocBuilder));
|
||||
} else if (example != null) {
|
||||
examples.put(responseEntry.getKey(), example);
|
||||
if (schema != null) {
|
||||
example = schema.getExample();
|
||||
|
||||
if (example == null && schema instanceof RefProperty) {
|
||||
String simpleRef = ((RefProperty) schema).getSimpleRef();
|
||||
example = generateExampleForRefModel(generateMissingExamples, simpleRef, definitions, markupDocBuilder);
|
||||
}
|
||||
if (example == null && generateMissingExamples) {
|
||||
example = PropertyUtils.exampleFromType(schema.getType(), schema, markupDocBuilder);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (example != null)
|
||||
examples.put(responseEntry.getKey(), example);
|
||||
|
||||
}
|
||||
if (examples.size() == 0) {
|
||||
return Optional.absent();
|
||||
}
|
||||
return Optional.of(examples);
|
||||
|
||||
return examples;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -60,13 +77,14 @@ public class ExamplesUtil {
|
||||
* @param pathOperation the Swagger Operation
|
||||
* @return an Optional with the example content
|
||||
*/
|
||||
public static Optional<Map<String, Object>> generateRequestExampleMap(PathOperation pathOperation, Map<String, Model> definitions, MarkupDocBuilder markupDocBuilder) {
|
||||
public static Map<String, Object> generateRequestExampleMap(boolean generateMissingExamples, PathOperation pathOperation, Map<String, Model> definitions, MarkupDocBuilder markupDocBuilder) {
|
||||
Operation operation = pathOperation.getOperation();
|
||||
List<Parameter> parameters = operation.getParameters();
|
||||
Map<String, Object> examples = new HashMap<>();
|
||||
|
||||
//Path example should always be included:
|
||||
examples.put("path", pathOperation.getPath());
|
||||
// Path example should always be included (if generateMissingExamples):
|
||||
if (generateMissingExamples)
|
||||
examples.put("path", pathOperation.getPath());
|
||||
for (Parameter parameter : parameters) {
|
||||
Object example = null;
|
||||
if (parameter instanceof BodyParameter) {
|
||||
@@ -75,62 +93,64 @@ public class ExamplesUtil {
|
||||
Model schema = ((BodyParameter) parameter).getSchema();
|
||||
if (schema instanceof RefModel) {
|
||||
String simpleRef = ((RefModel) schema).getSimpleRef();
|
||||
example = generateExampleForRefModel(simpleRef, definitions, markupDocBuilder);
|
||||
} else if (schema instanceof ComposedModel) {
|
||||
example = exampleMapForProperties(getPropertiesForComposedModel(
|
||||
(ComposedModel) schema, definitions), definitions, markupDocBuilder);
|
||||
} else if (schema instanceof ArrayModel) {
|
||||
example = generateExampleForArrayModel((ArrayModel) schema, definitions, markupDocBuilder);
|
||||
} else {
|
||||
example = schema.getExample();
|
||||
if (example == null) {
|
||||
example = exampleMapForProperties(schema.getProperties(), definitions, markupDocBuilder);
|
||||
example = generateExampleForRefModel(generateMissingExamples, simpleRef, definitions, markupDocBuilder);
|
||||
} else if (generateMissingExamples) {
|
||||
if (schema instanceof ComposedModel) {
|
||||
example = exampleMapForProperties(getPropertiesForComposedModel(
|
||||
(ComposedModel) schema, definitions), definitions, markupDocBuilder);
|
||||
} else if (schema instanceof ArrayModel) {
|
||||
example = generateExampleForArrayModel((ArrayModel) schema, definitions, markupDocBuilder);
|
||||
} else {
|
||||
example = schema.getExample();
|
||||
if (example == null) {
|
||||
example = exampleMapForProperties(schema.getProperties(), definitions, markupDocBuilder);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (parameter instanceof AbstractSerializableParameter) {
|
||||
Object abstractSerializableParameterExample;
|
||||
abstractSerializableParameterExample = ((AbstractSerializableParameter) parameter).getExample();
|
||||
if (abstractSerializableParameterExample == null) {
|
||||
Property item = ((AbstractSerializableParameter) parameter).getItems();
|
||||
if (item != null) {
|
||||
abstractSerializableParameterExample = convertStringToType((String) item.getExample(), item.getType());
|
||||
if (generateMissingExamples) {
|
||||
Object abstractSerializableParameterExample;
|
||||
abstractSerializableParameterExample = ((AbstractSerializableParameter) parameter).getExample();
|
||||
if (abstractSerializableParameterExample == null) {
|
||||
Property item = ((AbstractSerializableParameter) parameter).getItems();
|
||||
if (item != null) {
|
||||
abstractSerializableParameterExample = convertStringToType(item.getExample(), item.getType());
|
||||
if (abstractSerializableParameterExample == null) {
|
||||
abstractSerializableParameterExample = PropertyUtils.exampleFromType(item.getType(), item, markupDocBuilder);
|
||||
}
|
||||
}
|
||||
if (abstractSerializableParameterExample == null) {
|
||||
abstractSerializableParameterExample = PropertyUtils.exampleFromType(item.getType(), item, markupDocBuilder);
|
||||
abstractSerializableParameterExample = PropertyUtils.exampleFromType(((AbstractSerializableParameter) parameter).getType(), null, markupDocBuilder);
|
||||
}
|
||||
}
|
||||
if (abstractSerializableParameterExample == null) {
|
||||
abstractSerializableParameterExample = PropertyUtils.exampleFromType(((AbstractSerializableParameter) parameter).getType(), null, markupDocBuilder);
|
||||
if (parameter instanceof PathParameter) {
|
||||
String pathExample = (String) examples.get("path");
|
||||
pathExample = pathExample.replace('{' + parameter.getName() + '}', String.valueOf(abstractSerializableParameterExample));
|
||||
example = pathExample;
|
||||
} else {
|
||||
example = abstractSerializableParameterExample;
|
||||
}
|
||||
}
|
||||
if (parameter instanceof PathParameter) {
|
||||
String pathExample = (String) examples.get("path");
|
||||
MarkupDocBuilder italicString = markupDocBuilder.copy().italicText(String.valueOf(abstractSerializableParameterExample));
|
||||
pathExample = pathExample.replace('{' + parameter.getName() + '}', '*' + italicString.toString() + "*");
|
||||
example = pathExample;
|
||||
} else {
|
||||
example = abstractSerializableParameterExample;
|
||||
}
|
||||
if (parameter instanceof QueryParameter) {
|
||||
//noinspection unchecked
|
||||
Map<String, Object> queryExampleMap = (Map<String, Object>) examples.get("query");
|
||||
if (queryExampleMap == null) {
|
||||
queryExampleMap = new HashMap<>();
|
||||
if (parameter instanceof QueryParameter) {
|
||||
//noinspection unchecked
|
||||
Map<String, Object> queryExampleMap = (Map<String, Object>) examples.get("query");
|
||||
if (queryExampleMap == null) {
|
||||
queryExampleMap = new HashMap<>();
|
||||
}
|
||||
queryExampleMap.put(parameter.getName(), abstractSerializableParameterExample);
|
||||
example = queryExampleMap;
|
||||
}
|
||||
queryExampleMap.put(parameter.getName(), abstractSerializableParameterExample);
|
||||
example = queryExampleMap;
|
||||
}
|
||||
} else if (parameter instanceof RefParameter) {
|
||||
String simpleRef = ((RefParameter) parameter).getSimpleRef();
|
||||
example = generateExampleForRefModel(simpleRef, definitions, markupDocBuilder);
|
||||
example = generateExampleForRefModel(generateMissingExamples, simpleRef, definitions, markupDocBuilder);
|
||||
}
|
||||
examples.put(parameter.getIn(), example);
|
||||
|
||||
if (example != null)
|
||||
examples.put(parameter.getIn(), example);
|
||||
}
|
||||
|
||||
if (examples.size() == 0) {
|
||||
return Optional.absent();
|
||||
}
|
||||
return Optional.of(examples);
|
||||
return examples;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -139,12 +159,12 @@ public class ExamplesUtil {
|
||||
* @param simpleRef the simple reference string
|
||||
* @return returns an Object or Map of examples
|
||||
*/
|
||||
public static Object generateExampleForRefModel(String simpleRef, Map<String, Model> definitions, MarkupDocBuilder markupDocBuilder) {
|
||||
public static Object generateExampleForRefModel(boolean generateMissingExamples, String simpleRef, Map<String, Model> definitions, MarkupDocBuilder markupDocBuilder) {
|
||||
Model model = definitions.get(simpleRef);
|
||||
Object example = null;
|
||||
if (model != null) {
|
||||
example = model.getExample();
|
||||
if (example == null) {
|
||||
if (example == null && generateMissingExamples) {
|
||||
if (model instanceof ComposedModel) {
|
||||
example = exampleMapForProperties(getPropertiesForComposedModel((ComposedModel) model, definitions), definitions, markupDocBuilder);
|
||||
} else {
|
||||
@@ -158,12 +178,15 @@ public class ExamplesUtil {
|
||||
private static Map<String, Property> getPropertiesForComposedModel(ComposedModel model, Map<String, Model> definitions) {
|
||||
Map<String, Property> combinedProperties;
|
||||
if (model.getParent() instanceof RefModel) {
|
||||
combinedProperties = definitions.get(((RefModel) model.getParent()).getSimpleRef()).getProperties();
|
||||
if (combinedProperties == null) {
|
||||
Map<String, Property> parentProperties = definitions.get(((RefModel) model.getParent()).getSimpleRef()).getProperties();
|
||||
if (parentProperties == null) {
|
||||
return null;
|
||||
} else {
|
||||
combinedProperties = new LinkedHashMap<>(parentProperties);
|
||||
}
|
||||
|
||||
} else {
|
||||
combinedProperties = model.getParent().getProperties();
|
||||
combinedProperties = new LinkedHashMap<>(model.getParent().getProperties());
|
||||
}
|
||||
Map<String, Property> childProperties;
|
||||
if (model.getChild() instanceof RefModel) {
|
||||
@@ -186,11 +209,11 @@ public class ExamplesUtil {
|
||||
*/
|
||||
public static Map<String, Object> exampleMapForProperties(Map<String, Property> properties, Map<String, Model> definitions, MarkupDocBuilder markupDocBuilder) {
|
||||
Map<String, Object> exampleMap = new HashMap<>();
|
||||
for (Map.Entry<String,Property> property : properties.entrySet()) {
|
||||
for (Map.Entry<String, Property> property : properties.entrySet()) {
|
||||
Object exampleObject = convertStringToType(property.getValue().getExample(), property.getValue().getType());
|
||||
if (exampleObject == null) {
|
||||
if (property.getValue() instanceof RefProperty) {
|
||||
exampleObject = generateExampleForRefModel(((RefProperty) property.getValue()).getSimpleRef(), definitions, markupDocBuilder);
|
||||
exampleObject = generateExampleForRefModel(true, ((RefProperty) property.getValue()).getSimpleRef(), definitions, markupDocBuilder);
|
||||
} else if (property.getValue() instanceof ArrayProperty) {
|
||||
exampleObject = generateExampleForArrayProperty((ArrayProperty) property.getValue(), definitions, markupDocBuilder);
|
||||
} else if (property.getValue() instanceof MapProperty) {
|
||||
@@ -223,17 +246,17 @@ public class ExamplesUtil {
|
||||
if (model.getExample() != null) {
|
||||
return model.getExample();
|
||||
} else if (model.getProperties() != null) {
|
||||
return new Object[] {exampleMapForProperties(model.getProperties(), definitions, markupDocBuilder)};
|
||||
return new Object[]{exampleMapForProperties(model.getProperties(), definitions, markupDocBuilder)};
|
||||
} else {
|
||||
Property itemProperty = model.getItems();
|
||||
if (itemProperty.getExample() != null) {
|
||||
return new Object[] { convertStringToType(itemProperty.getExample(), itemProperty.getType()) };
|
||||
return new Object[]{convertStringToType(itemProperty.getExample(), itemProperty.getType())};
|
||||
} else if (itemProperty instanceof ArrayProperty) {
|
||||
return new Object[] { generateExampleForArrayProperty((ArrayProperty) itemProperty, definitions, markupDocBuilder) };
|
||||
return new Object[]{generateExampleForArrayProperty((ArrayProperty) itemProperty, definitions, markupDocBuilder)};
|
||||
} else if (itemProperty instanceof RefProperty) {
|
||||
return new Object[] { generateExampleForRefModel(((RefProperty) itemProperty).getSimpleRef(), definitions, markupDocBuilder) };
|
||||
return new Object[]{generateExampleForRefModel(true, ((RefProperty) itemProperty).getSimpleRef(), definitions, markupDocBuilder)};
|
||||
} else {
|
||||
return new Object[] { PropertyUtils.exampleFromType(itemProperty.getType(), itemProperty, markupDocBuilder) };
|
||||
return new Object[]{PropertyUtils.exampleFromType(itemProperty.getType(), itemProperty, markupDocBuilder)};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -247,13 +270,13 @@ public class ExamplesUtil {
|
||||
public static Object[] generateExampleForArrayProperty(ArrayProperty value, Map<String, Model> definitions, MarkupDocBuilder markupDocBuilder) {
|
||||
Property property = value.getItems();
|
||||
if (property.getExample() != null) {
|
||||
return new Object[] {convertStringToType(property.getExample(), property.getType())};
|
||||
return new Object[]{convertStringToType(property.getExample(), property.getType())};
|
||||
} else if (property instanceof ArrayProperty) {
|
||||
return new Object[] {generateExampleForArrayProperty((ArrayProperty) property, definitions, markupDocBuilder)};
|
||||
return new Object[]{generateExampleForArrayProperty((ArrayProperty) property, definitions, markupDocBuilder)};
|
||||
} else if (property instanceof RefProperty) {
|
||||
return new Object[] {generateExampleForRefModel(((RefProperty) property).getSimpleRef(), definitions, markupDocBuilder)};
|
||||
return new Object[]{generateExampleForRefModel(true, ((RefProperty) property).getSimpleRef(), definitions, markupDocBuilder)};
|
||||
} else {
|
||||
return new Object[] {PropertyUtils.exampleFromType(property.getType(), property, markupDocBuilder)};
|
||||
return new Object[]{PropertyUtils.exampleFromType(property.getType(), property, markupDocBuilder)};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -270,7 +293,7 @@ public class ExamplesUtil {
|
||||
case "boolean":
|
||||
return new Boolean(value);
|
||||
case "string":
|
||||
return value;
|
||||
return value;
|
||||
default:
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.github.robwin.swagger2markup.utils;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Copyright 2015 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.github.robwin.swagger2markup.utils;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import io.github.robwin.swagger2markup.type.*;
|
||||
import io.github.robwin.swagger2markup.type.ArrayType;
|
||||
import io.github.robwin.swagger2markup.type.ObjectType;
|
||||
import io.github.robwin.swagger2markup.type.RefType;
|
||||
import io.github.robwin.swagger2markup.type.Type;
|
||||
import io.swagger.models.ArrayModel;
|
||||
import io.swagger.models.Model;
|
||||
import io.swagger.models.ModelImpl;
|
||||
|
||||
@@ -1,20 +1,17 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Copyright 2015 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.github.robwin.swagger2markup.utils;
|
||||
|
||||
|
||||
@@ -1,20 +1,17 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Copyright 2015 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.github.robwin.swagger2markup.utils;
|
||||
|
||||
@@ -27,10 +24,7 @@ import io.swagger.util.Json;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.*;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||
|
||||
@@ -43,7 +37,7 @@ public final class PropertyUtils {
|
||||
* @return the type of the property
|
||||
*/
|
||||
public static Type getType(Property property, Function<String, String> definitionDocumentResolver) {
|
||||
Validate.notNull(property, "property must not be null!");
|
||||
Validate.notNull(property, "property must not be null");
|
||||
Type type;
|
||||
if (property instanceof RefProperty) {
|
||||
RefProperty refProperty = (RefProperty) property;
|
||||
@@ -82,7 +76,7 @@ public final class PropertyUtils {
|
||||
* @return the default value of the property, or otherwise an empty String
|
||||
*/
|
||||
public static String getDefaultValue(Property property) {
|
||||
Validate.notNull(property, "property must not be null!");
|
||||
Validate.notNull(property, "property must not be null");
|
||||
String defaultValue = "";
|
||||
if (property instanceof BooleanProperty) {
|
||||
BooleanProperty booleanProperty = (BooleanProperty) property;
|
||||
@@ -109,8 +103,15 @@ public final class PropertyUtils {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return example display string for the given {@code property}.
|
||||
*
|
||||
* @param property property
|
||||
* @param markupDocBuilder doc builder
|
||||
* @return property example display string
|
||||
*/
|
||||
public static String getExample(Property property, MarkupDocBuilder markupDocBuilder) {
|
||||
Validate.notNull(property, "parameter must not be null!");
|
||||
Validate.notNull(property, "property must not be null");
|
||||
Object examplesValue;
|
||||
if (property.getExample() != null) {
|
||||
examplesValue = property.getExample();
|
||||
@@ -124,10 +125,12 @@ public final class PropertyUtils {
|
||||
examplesValue = Json.pretty(exampleMap);
|
||||
}
|
||||
} else if (property instanceof ArrayProperty) {
|
||||
List<Object> exampleArray = new ArrayList<>();
|
||||
Property itemProperty = ((ArrayProperty) property).getItems();
|
||||
examplesValue = "[ " + exampleFromType(itemProperty.getType(), itemProperty, markupDocBuilder) + " ]";
|
||||
exampleArray.add(exampleFromType(itemProperty.getType(), itemProperty, markupDocBuilder));
|
||||
examplesValue = Json.pretty(exampleArray);
|
||||
} else {
|
||||
examplesValue = exampleFromType(property.getType(), property, markupDocBuilder);
|
||||
examplesValue = Json.pretty(exampleFromType(property.getType(), property, markupDocBuilder));
|
||||
}
|
||||
return String.valueOf(examplesValue);
|
||||
}
|
||||
|
||||
@@ -1,20 +1,17 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Copyright 2015 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.github.robwin.swagger2markup.utils;
|
||||
|
||||
@@ -23,12 +20,8 @@ import com.google.common.collect.Multimap;
|
||||
import com.google.common.collect.MultimapBuilder;
|
||||
import com.google.common.collect.Ordering;
|
||||
import io.github.robwin.swagger2markup.PathOperation;
|
||||
import io.swagger.models.HttpMethod;
|
||||
import io.swagger.models.Operation;
|
||||
import io.swagger.models.Path;
|
||||
import io.swagger.models.Tag;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
swagger2markup.markupLanguage=ASCIIDOC
|
||||
swagger2markup.examplesEnabled=false
|
||||
swagger2markup.generatedExamplesEnabled=false
|
||||
swagger2markup.schemasEnabled=false
|
||||
swagger2markup.operationDescriptionsEnabled=false
|
||||
swagger2markup.definitionDescriptionsEnabled=false
|
||||
|
||||
@@ -1,20 +1,17 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Copyright 2015 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.github.robwin.swagger2markup;
|
||||
|
||||
@@ -111,7 +108,6 @@ public class Swagger2MarkupConverterTest {
|
||||
|
||||
//When
|
||||
Swagger2MarkupConfig config = Swagger2MarkupConfig.ofDefaults()
|
||||
.withExamples()
|
||||
.build();
|
||||
|
||||
Swagger2MarkupConverter.from(swaggerJsonString)
|
||||
@@ -121,12 +117,142 @@ public class Swagger2MarkupConverterTest {
|
||||
|
||||
//Then
|
||||
String[] directories = outputDirectory.toFile().list();
|
||||
assertThat(new String(Files.readAllBytes(outputDirectory.resolve("paths.adoc"))))
|
||||
.contains("==== Example HTTP response");
|
||||
assertThat(new String(Files.readAllBytes(outputDirectory.resolve("definitions.adoc"))))
|
||||
.contains("|name||true|string||doggie");
|
||||
String orderExample = "----\n" +
|
||||
"{\n" +
|
||||
" \"id\" : 99,\n" +
|
||||
" \"petId\" : 122,\n" +
|
||||
" \"quantity\" : 2,\n" +
|
||||
" \"shipDate\" : \"2016-02-22T23:02:05Z\",\n" +
|
||||
" \"status\" : \"PENDING\",\n" +
|
||||
" \"complete\" : true\n" +
|
||||
"}\n" +
|
||||
"----\n";
|
||||
String petResponseExample = "----\n" +
|
||||
"{\n" +
|
||||
" \"application/json\" : {\n" +
|
||||
" \"name\" : \"Puma\",\n" +
|
||||
" \"type\" : 22,\n" +
|
||||
" \"color\" : \"Black\",\n" +
|
||||
" \"gender\" : \"Female\",\n" +
|
||||
" \"breed\" : \"Mixed\"\n" +
|
||||
" }\n" +
|
||||
"}\n" +
|
||||
"----\n";
|
||||
|
||||
String pathsDocument = new String(Files.readAllBytes(outputDirectory.resolve("paths.adoc")));
|
||||
assertThat(pathsDocument)
|
||||
.contains("==== Response 405\n" + petResponseExample);
|
||||
assertThat(pathsDocument)
|
||||
.contains("==== Request body\n" + orderExample);
|
||||
assertThat(pathsDocument)
|
||||
.contains("==== Response 200\n" + orderExample);
|
||||
|
||||
String definitionsDocument = new String(Files.readAllBytes(outputDirectory.resolve("definitions.adoc")));
|
||||
assertThat(definitionsDocument)
|
||||
.contains("|id||false|integer(int64)||77");
|
||||
assertThat(definitionsDocument).contains("|pictures||false|string(byte) array||[ \"string\" ]");
|
||||
assertThat(definitionsDocument).contains("|shipDate||false|string(date-time)||\"string\"");
|
||||
assertThat(definitionsDocument)
|
||||
.doesNotContain("99");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSwagger2AsciiDocConversionWithGeneratedExamples() throws IOException {
|
||||
//Given
|
||||
String swaggerJsonString = IOUtils.toString(getClass().getResourceAsStream("/json/swagger_examples.json"));
|
||||
Path outputDirectory = Paths.get("build/docs/asciidoc/generated");
|
||||
FileUtils.deleteQuietly(outputDirectory.toFile());
|
||||
|
||||
//When
|
||||
Swagger2MarkupConfig config = Swagger2MarkupConfig.ofDefaults()
|
||||
.withGeneratedExamples()
|
||||
.build();
|
||||
|
||||
Swagger2MarkupConverter.from(swaggerJsonString)
|
||||
.withConfig(config)
|
||||
.build()
|
||||
.intoFolder(outputDirectory);
|
||||
|
||||
//Then
|
||||
String[] directories = outputDirectory.toFile().list();
|
||||
String petGeneratedExample = "----\n" +
|
||||
"{\n" +
|
||||
" \"tags\" : [ {\n" +
|
||||
" \"id\" : 0,\n" +
|
||||
" \"name\" : \"string\"\n" +
|
||||
" } ],\n" +
|
||||
" \"id\" : 0,\n" +
|
||||
" \"nicknames\" : {\n" +
|
||||
" \"string\" : \"string\"\n" +
|
||||
" },\n" +
|
||||
" \"category\" : {\n" +
|
||||
" \"id\" : 123,\n" +
|
||||
" \"name\" : \"Canines\"\n" +
|
||||
" },\n" +
|
||||
" \"weight\" : 0.0,\n" +
|
||||
" \"status\" : \"string\",\n" +
|
||||
" \"name\" : \"doggie\",\n" +
|
||||
" \"photoUrls\" : [ \"string\" ]\n" +
|
||||
"}\n" +
|
||||
"----\n";
|
||||
String petResponseExample = "----\n" +
|
||||
"{\n" +
|
||||
" \"application/json\" : {\n" +
|
||||
" \"name\" : \"Puma\",\n" +
|
||||
" \"type\" : 22,\n" +
|
||||
" \"color\" : \"Black\",\n" +
|
||||
" \"gender\" : \"Female\",\n" +
|
||||
" \"breed\" : \"Mixed\"\n" +
|
||||
" }\n" +
|
||||
"}\n" +
|
||||
"----\n";
|
||||
String pathsDocument = new String(Files.readAllBytes(outputDirectory.resolve("paths.adoc")));
|
||||
assertThat(pathsDocument)
|
||||
.contains("==== Request body\n" + petGeneratedExample);
|
||||
assertThat(pathsDocument)
|
||||
.contains("== Request path\n" + "----\n" +
|
||||
"\"/pets\"\n" +
|
||||
"----");
|
||||
assertThat(pathsDocument)
|
||||
.contains("==== Request query\n" +
|
||||
"----\n" +
|
||||
"{\n" +
|
||||
" \"status\" : \"string\"\n" +
|
||||
"}\n" +
|
||||
"----\n");
|
||||
assertThat(pathsDocument)
|
||||
.contains("==== Response 405\n" + petResponseExample);
|
||||
assertThat(pathsDocument)
|
||||
.contains("==== Response 200\n" +
|
||||
"----\n" +
|
||||
"\"array\"\n" +
|
||||
"----");
|
||||
assertThat(pathsDocument)
|
||||
.contains("==== Request path\n" +
|
||||
"----\n" +
|
||||
"\"/pets/0\"\n" +
|
||||
"----");
|
||||
|
||||
String definitionsDocument = new String(Files.readAllBytes(outputDirectory.resolve("definitions.adoc")));
|
||||
assertThat(definitionsDocument)
|
||||
.contains("|id||false|integer(int64)||77");
|
||||
assertThat(definitionsDocument)
|
||||
.contains("|name||true|string||doggie");
|
||||
assertThat(definitionsDocument)
|
||||
.contains("|nicknames||false|object||{\n" +
|
||||
" \"string\" : \"string\"\n" +
|
||||
"}");
|
||||
assertThat(definitionsDocument)
|
||||
.contains("[options=\"header\", cols=\".^1h,.^6,.^1,.^1,.^1,.^1\"]\n" +
|
||||
"|===\n" +
|
||||
"|Name|Description|Required|Schema|Default|Example\n" +
|
||||
"|id||false|integer(int64)||0\n" +
|
||||
"|===\n");
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSwagger2AsciiDocConversionAsString() throws IOException, URISyntaxException {
|
||||
//Given
|
||||
|
||||
@@ -1,20 +1,17 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Copyright 2015 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.github.robwin.swagger2markup.config;
|
||||
|
||||
@@ -45,7 +42,7 @@ public class Swagger2MarkupConfigTest {
|
||||
assertThat(config.getOperationDescriptionsUri()).isNull();
|
||||
assertThat(config.isDefinitionDescriptionsEnabled()).isFalse();
|
||||
assertThat(config.getDefinitionDescriptionsUri()).isNull();
|
||||
assertThat(config.isExamplesEnabled()).isFalse();
|
||||
assertThat(config.isGeneratedExamplesEnabled()).isFalse();
|
||||
assertThat(config.getInlineSchemaDepthLevel()).isEqualTo(0);
|
||||
assertThat(config.getInterDocumentCrossReferencesPrefix()).isNull();
|
||||
assertThat(config.getMarkupLanguage()).isEqualTo(MarkupLanguage.ASCIIDOC);
|
||||
@@ -91,7 +88,7 @@ public class Swagger2MarkupConfigTest {
|
||||
assertThat(config.getOperationDescriptionsUri()).isEqualTo(URI.create("operationDescriptions"));
|
||||
assertThat(config.isDefinitionDescriptionsEnabled()).isTrue();
|
||||
assertThat(config.getDefinitionDescriptionsUri()).isEqualTo(URI.create("definitionDescriptions"));
|
||||
assertThat(config.isExamplesEnabled()).isTrue();
|
||||
assertThat(config.isGeneratedExamplesEnabled()).isTrue();
|
||||
assertThat(config.getInlineSchemaDepthLevel()).isEqualTo(2);
|
||||
assertThat(config.getInterDocumentCrossReferencesPrefix()).isEqualTo("xrefPrefix");
|
||||
assertThat(config.getMarkupLanguage()).isEqualTo(MarkupLanguage.MARKDOWN);
|
||||
|
||||
@@ -1,20 +1,17 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Copyright 2015 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.github.robwin.swagger2markup.extension;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
swagger2markup.markupLanguage=MARKDOWN
|
||||
swagger2markup.examplesEnabled=true
|
||||
swagger2markup.generatedExamplesEnabled=true
|
||||
swagger2markup.schemasUri=schemas
|
||||
swagger2markup.schemasEnabled=true
|
||||
swagger2markup.operationDescriptionsEnabled=true
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user