Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,15 @@ public String toEnumValue(String value, String datatype) {
}
}

@Override
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, Map<String, Model> definitions, Swagger swagger) {
CodegenOperation op = super.fromOperation(path, httpMethod, operation, definitions, swagger);

op.path = sanitizePath(op.path);

return op;
}

private static CodegenModel reconcileInlineEnums(CodegenModel codegenModel, CodegenModel parentCodegenModel) {
// This generator uses inline classes to define enums, which breaks when
// dealing with models that have subTypes. To clean this up, we will analyze
Expand Down Expand Up @@ -811,6 +820,11 @@ public void setSerializableModel(Boolean serializableModel) {
this.serializableModel = serializableModel;
}

private String sanitizePath(String p) {
//prefer replace a ", instead of a fuLL URL encode for readability
return p.replaceAll("\"", "%22");
}

public void setFullJavaUtil(boolean fullJavaUtil) {
this.fullJavaUtil = fullJavaUtil;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,9 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation
op.returnType = normalizeType(op.returnType);
}

//path is an unescaped variable in the mustache template api.mustache line 82 '<&path>'
op.path = sanitizePath(op.path);

// Set vendor-extension to be used in template:
// x-codegen-hasMoreRequired
// x-codegen-hasMoreOptional
Expand Down Expand Up @@ -738,6 +741,11 @@ public CodegenModel fromModel(String name, Model model, Map<String, Model> allDe
return codegenModel;
}

private String sanitizePath(String p) {
//prefer replace a ', instead of a fuLL URL encode for readability
return p.replaceAll("'", "%27");
}

private String trimBrackets(String s) {
if (s != null) {
int beginIdx = s.charAt(0) == '[' ? 1 : 0;
Expand Down
14 changes: 8 additions & 6 deletions modules/swagger-codegen/src/main/resources/php/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,10 @@ use \{{invokerPackage}}\ObjectSerializer;
* Operation {{{operationId}}}
*
* {{{summary}}}.
*
{{#allParams}} * @param {{dataType}} ${{paramName}} {{description}} {{#required}}(required){{/required}}{{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}
{{/allParams}} *
*/
{{#allParams}} // * @param {{dataType}} ${{paramName}} {{description}} {{#required}}(required){{/required}}{{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}
{{/allParams}}
/**
* @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}
* @throws \{{invokerPackage}}\ApiException on non-2xx response
*/
Expand All @@ -103,9 +104,10 @@ use \{{invokerPackage}}\ObjectSerializer;
* Operation {{{operationId}}}WithHttpInfo
*
* {{{summary}}}.
*
{{#allParams}} * @param {{dataType}} ${{paramName}} {{description}} {{#required}}(required){{/required}}{{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}
{{/allParams}} *
*/
{{#allParams}} // * @param {{dataType}} ${{paramName}} {{description}} {{#required}}(required){{/required}}{{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}
{{/allParams}}
/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not knowing PHP that well, this looks like not the correct syntax for a documentation comment. (Might be acceptable for fixing the vulnerability, but should be changed later so something better, e.g. using a similar approach as for the other languages.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ePaul Thank you! The intent for to force it as single line, though I am very open to suggestions on modification here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sdavis-r7 I'll probably keep * and sanitize the tag to remove line break instead so as to conform to the PHP coding style.

* @return Array of {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}null{{/returnType}}, HTTP status code, HTTP response headers (array of strings)
* @throws \{{invokerPackage}}\ApiException on non-2xx response
*/
Expand Down
10 changes: 6 additions & 4 deletions modules/swagger-codegen/src/main/resources/php/model.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ use \ArrayAccess;
/**
* {{classname}} Class Doc Comment
*
* @category Class
* @category Class */
{{#description}}
* @description {{description}}
// @description {{description}}
{{/description}}
/**
* @package {{invokerPackage}}
* @author http://github.com/swagger-api/swagger-codegen
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache Licene v2
Expand Down Expand Up @@ -258,8 +259,9 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}imple
}

/**
* Sets {{name}}
* @param {{datatype}} ${{name}}{{#description}} {{{description}}}{{/description}}
* Sets {{name}} */
// * @param {{datatype}} ${{name}}{{#description}} {{{description}}}{{/description}}
/**
* @return $this
*/
public function {{setter}}(${{name}})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}implements ArrayA
{{/isEnum}}{{/vars}}

{{#vars}}
/**/
//* ${{name}} {{#description}}{{{description}}}{{/description}}
/**
* ${{name}} {{#description}}{{{description}}}{{/description}}
* @var {{datatype}}
*/
protected ${{name}}{{#defaultValue}} = {{{defaultValue}}}{{/defaultValue}};
Expand Down Expand Up @@ -104,8 +105,9 @@ class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}implements ArrayA
}

/**
* Sets {{name}}.
* @param {{datatype}} ${{name}} {{#description}}{{{description}}}{{/description}}
* Sets {{name}}. */
//* @param {{datatype}} ${{name}} {{#description}}{{{description}}}{{/description}}
/**
* @return $this
*/
public function {{setter}}(${{name}})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ namespace {{modelPackage}};
/**
* {{classname}}Test Class Doc Comment
*
* @category Class
* @description {{#description}}{{description}}{{/description}}{{^description}}{{classname}}{{/description}}
* @category Class */
// * @description {{#description}}{{description}}{{/description}}{{^description}}{{classname}}{{/description}}
/**
* @package {{invokerPackage}}
* @author http://github.com/swagger-api/swagger-codegen
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache Licene v2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
{{#appName}}
* {{{appName}}}
*
{{/appName}}
{{/appName}} */
{{#appDescription}}
* {{{appDescription}}}
*
//* {{{appDescription}}}
{{/appDescription}}
* {{#version}}OpenAPI spec version: {{{version}}}{{/version}}
/* {{#version}}OpenAPI spec version: {{{version}}}{{/version}}
* {{#infoEmail}}Contact: {{{infoEmail}}}{{/infoEmail}}
* Generated by: https://github.com/swagger-api/swagger-codegen.git
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{{#appName}}
{{{appName}}}
#{{{appName}}}

{{/appName}}
{{#appDescription}}
{{{appDescription}}}
#{{{appDescription}}}

{{/appDescription}}
{{#version}}OpenAPI spec version: {{version}}{{/version}}
Expand Down