Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

typescript-axios anytype is not defined #6335

Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions bin/typescript-axios-petstore-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
./bin/typescript-axios-petstore-with-complex-headers.sh
./bin/typescript-axios-petstore-with-single-request-parameters.sh
./bin/typescript-axios-petstore-interfaces.sh
./bin/typescript-axios-petstore-allOf-without-properties.sh
./bin/typescript-axios-petstore.sh
32 changes: 32 additions & 0 deletions bin/typescript-axios-petstore-allOf-without-properties.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/sh

SCRIPT="$0"
echo "# START SCRIPT: $SCRIPT"

while [ -h "$SCRIPT" ] ; do
ls=`ls -ld "$SCRIPT"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
SCRIPT="$link"
else
SCRIPT=`dirname "$SCRIPT"`/"$link"
fi
done

if [ ! -d "${APP_DIR}" ]; then
APP_DIR=`dirname "$SCRIPT"`/..
APP_DIR=`cd "${APP_DIR}"; pwd`
fi

executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar"

if [ ! -f "$executable" ]
then
mvn -B clean package
fi

# if you've executed sbt assembly previously it will use that instead.
export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties"
ags="generate -i modules/openapi-generator/src/test/resources/3_0/allOf-without-properties.yaml -g typescript-axios -o samples/client/petstore/typescript-axios/builds/allOf-without-properties $@"

java $JAVA_OPTS -jar $executable $ags
1 change: 1 addition & 0 deletions bin/windows/typescript-axios-petstore-all.bat
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ call bin\windows\typescript-axios-petstore-with-complex-headers.bat
call bin\windows\typescript-axios-petstore-with-single-request-parameters.bat
call bin\windows\typescript-axios-petstore-with-npm-version.bat
call bin\windows\typescript-axios-petstore-interfaces.bat
call bin\windows\typescript-axios-petstore-allOf-without-properties.bat
call bin\windows\typescript-axios-petstore-with-npm-version-and-separate-models-and-api.bat
14 changes: 14 additions & 0 deletions bin/windows/typescript-axios-petstore-allOf-without-properties.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@ECHO OFF

set executable=.\modules\openapi-generator-cli\target\openapi-generator-cli.jar

If Not Exist %executable% (
mvn clean package
)

REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M

echo
set ags=generate -i modules\openapi-generator\src\test\resources\3_0\allOf-without-properties.yaml -g typescript-axios -o samples\client\petstore\typescript-axios\builds\allOf-without-properties

java %JAVA_OPTS% -jar %executable% %ags%
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ public AbstractTypeScriptClientCodegen() {
typeMapping.put("UUID", "string");
typeMapping.put("URI", "string");
typeMapping.put("Error", "Error");
typeMapping.put("AnyType", "any");

cliOptions.add(new CliOption(CodegenConstants.ENUM_NAME_SUFFIX, CodegenConstants.ENUM_NAME_SUFFIX_DESC).defaultValue(this.enumSuffix));
cliOptions.add(new CliOption(CodegenConstants.ENUM_PROPERTY_NAMING, CodegenConstants.ENUM_PROPERTY_NAMING_DESC).defaultValue(this.enumPropertyNaming.name()));
Expand Down Expand Up @@ -808,35 +809,34 @@ public void postProcessFile(File file, String fileType) {

@Override
public String toAnyOfName(List<String> names, ComposedSchema composedSchema) {
List<String> types = composedSchema.getAnyOf().stream().map(schema -> {
String schemaType = getSchemaType(schema);
if (ModelUtils.isArraySchema(schema)) {
ArraySchema ap = (ArraySchema) schema;
Schema inner = ap.getItems();
schemaType = schemaType + "<" + getSchemaType(inner) + ">";
}
return schemaType;
}).distinct().collect(Collectors.toList());
List<String> types = getTypesFromSchemas(composedSchema.getAnyOf());

return String.join(" | ", types);
}

@Override
public String toOneOfName(List<String> names, ComposedSchema composedSchema) {
List<String> types = composedSchema.getOneOf().stream().map(schema -> {
String schemaType = getSchemaType(schema);
if (ModelUtils.isArraySchema(schema)) {
ArraySchema ap = (ArraySchema) schema;
Schema inner = ap.getItems();
schemaType = schemaType + "<" + getSchemaType(inner) + ">";
}
return schemaType;
}).distinct().collect(Collectors.toList());
List<String> types = getTypesFromSchemas(composedSchema.getOneOf());

return String.join(" | ", types);
}

@Override
public String toAllOfName(List<String> names, ComposedSchema composedSchema) {
List<String> types = composedSchema.getAllOf().stream().map(schema -> {
List<String> types = getTypesFromSchemas(composedSchema.getAllOf());

return String.join(" & ", types);
}

/**
* Extracts the list of type names from a list of schemas.
* Excludes `AnyType` if there are other valid types extracted.
*
* @param schema list of schemas
* @return list of types
*/
protected List<String> getTypesFromSchemas(List<Schema> schemas) {
List<String> types = schemas.stream().map(schema -> {
String schemaType = getSchemaType(schema);
if (ModelUtils.isArraySchema(schema)) {
ArraySchema ap = (ArraySchema) schema;
Expand All @@ -845,6 +845,11 @@ public String toAllOfName(List<String> names, ComposedSchema composedSchema) {
}
return schemaType;
}).distinct().collect(Collectors.toList());
return String.join(" & ", types);

if (types.size() > 1 && types.contains("any")) {
Copy link
Contributor

@amakhrov amakhrov May 16, 2020

Choose a reason for hiding this comment

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

nit: it might be simpler to add .filter() call to the stream instead of post-processing the resulting list.

EDIT: Aha, I was wrong here. Apparently, if we're about to return a single any type, it's ok - we only want to remove any when it's used in conjuction with some other type (in allOf/oneOf)

types.remove("any");
}

return types;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@


openapi: 3.0.1
info:
version: 1.0.0
title: Example
license:
name: MIT
servers:
- url: http://api.example.xyz/v1
paths:
/person/display/{personId}:
get:
parameters:
- name: personId
in: path
required: true
description: The id of the person to retrieve
schema:
type: string
operationId: list
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: "#/components/schemas/Person"
components:
schemas:
Person:
type: object
discriminator:
propertyName: $_type
mapping:
a: '#/components/schemas/Adult'
c: Child
properties:
$_type:
type: string
lastName:
type: string
firstName:
type: string
Adult:
description: A representation of an adult
allOf:
- $ref: '#/components/schemas/Person'
- type: object
properties:
children:
type: array
items:
$ref: "#/components/schemas/Child"
firstChild:
allOf:
- $ref: '#/components/schemas/Child'
# This field doesn't contain properties or ref, so it's not
# possible to determine type, thus it will be `AnyType`
- description: First child
Child:
description: A representation of a child
allOf:
- type: object
properties:
age:
type: integer
format: int32
- $ref: '#/components/schemas/Person'
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
wwwroot/*.js
node_modules
typings
dist
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# empty npmignore to ensure all required files (e.g., in the dist folder) are published by npm
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# OpenAPI Generator Ignore
# Generated by openapi-generator https://github.com/openapitools/openapi-generator

# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.

# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
#ApiClient.cs

# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux

# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux

# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5.0.0-SNAPSHOT
Loading