forked from loafle/openapi-generator-original
[Elixir] Improve Elixir client (#6550)
* Fix dependencies and generate model classes * Better elixir client generation. Responses are parsed and serialized by Poison into the model structs. Use shared helper functions to generate the request. Extract client connection configuration from api calls. Elixir client can sanitize the operationId Correctly output the model variables. Fix typos Fix path replacement when there are multiple replacements Cannot separate globally shared parameters from operations Error handling for the tesla response update templates Can generate clients that compile Can make requests - parse optional params, build query Add oauth to connection. Fix connection directory Add basic auth helper for creating a connection Fix map types. Fix guard clauses for creaing connections Add licenceInfo template. Parse config for moduleName via standard invokerPackage option Can provide and inject a license header into all source files fix location of connection.ex Move shared code into reusable modules Elixir filenames should be underscored Fix visibility of helper functions Parse the packageName from config options Handle date and datetime fields with DateTime.from_iso8601 Fix indentation Update documentation, add typespecs Generate a standard elixir .gitignore typespec is calculated recursively in java Use the JSON middleware and using Poison.Decoder.decode on already parsed structs move decoded struct into java Fix handling of non-json responses Switch basic auth to use the provided Tesla.Middleware.BasicAuth Update README template to include the appDescription Update sample elixir client remove junk client models that don't belong with petstore Only implement Poison.Decoder protocol if needed Update samples with skipped Poison.Deocder impl * Handle multipart file uploads Handle building form params in the body Files are handled as strings for input * Requests with no defined return type will return the Tesla.Env response * Run the bin/elixir-petstore.sh
This commit is contained in:
parent
3ac2b803f9
commit
4b9ee1f194
@ -6,6 +6,10 @@ import io.swagger.codegen.*;
|
||||
import io.swagger.models.properties.ArrayProperty;
|
||||
import io.swagger.models.properties.MapProperty;
|
||||
import io.swagger.models.properties.Property;
|
||||
import io.swagger.models.Info;
|
||||
import io.swagger.models.Model;
|
||||
import io.swagger.models.Swagger;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
@ -14,14 +18,17 @@ import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class ElixirClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
// source folder where to write the files
|
||||
protected String sourceFolder = "lib";
|
||||
protected String apiVersion = "1.0.0";
|
||||
protected String moduleName;
|
||||
protected static final String defaultModuleName = "Swagger.Client";
|
||||
|
||||
// This is the name of elixir project name;
|
||||
protected static final String defaultPackageName = "swagger_client";
|
||||
|
||||
String supportedElixirVersion = "1.4";
|
||||
List<String> extraApplications = Arrays.asList(":logger");
|
||||
List<String> deps = Arrays.asList(
|
||||
"{:tesla, \"~> 0.5.0\"}",
|
||||
"{:tesla, \"~> 0.8\"}",
|
||||
"{:poison, \">= 1.0.0\"}"
|
||||
);
|
||||
|
||||
@ -32,7 +39,7 @@ public class ElixirClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
// set the output folder here
|
||||
outputFolder = "generated-code/elixir";
|
||||
|
||||
/**
|
||||
/*
|
||||
* Models. You can write model files using the modelTemplateFiles map.
|
||||
* if you want to create one template for file, you can do so here.
|
||||
* for multiple files for model, just put another entry in the `modelTemplateFiles` with
|
||||
@ -62,8 +69,14 @@ public class ElixirClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
*/
|
||||
reservedWords = new HashSet<String>(
|
||||
Arrays.asList(
|
||||
"sample1", // replace with static values
|
||||
"sample2")
|
||||
"nil",
|
||||
"true",
|
||||
"false",
|
||||
"__MODULE__",
|
||||
"__FILE__",
|
||||
"__DIR__",
|
||||
"__ENV__",
|
||||
"__CALLER__")
|
||||
);
|
||||
|
||||
/**
|
||||
@ -93,6 +106,10 @@ public class ElixirClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
"test",
|
||||
"test_helper.exs")
|
||||
);
|
||||
supportingFiles.add(new SupportingFile("gitignore.mustache",
|
||||
"",
|
||||
".gitignore")
|
||||
);
|
||||
|
||||
/**
|
||||
* Language Specific Primitives. These types will not trigger imports by
|
||||
@ -100,9 +117,43 @@ public class ElixirClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
*/
|
||||
languageSpecificPrimitives = new HashSet<String>(
|
||||
Arrays.asList(
|
||||
"Type1", // replace these with your types
|
||||
"Type2")
|
||||
"Integer",
|
||||
"Float",
|
||||
"Boolean",
|
||||
"String",
|
||||
"List",
|
||||
"Atom",
|
||||
"Map",
|
||||
"Tuple",
|
||||
"PID",
|
||||
"DateTime"
|
||||
)
|
||||
);
|
||||
|
||||
// ref: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#data-types
|
||||
typeMapping = new HashMap<String, String>();
|
||||
typeMapping.put("integer", "Integer");
|
||||
typeMapping.put("long", "Integer");
|
||||
typeMapping.put("number", "Float");
|
||||
typeMapping.put("float", "Float");
|
||||
typeMapping.put("double", "Float");
|
||||
typeMapping.put("string", "String");
|
||||
typeMapping.put("byte", "Integer");
|
||||
typeMapping.put("boolean", "Boolean");
|
||||
typeMapping.put("Date", "DateTime");
|
||||
typeMapping.put("DateTime", "DateTime");
|
||||
typeMapping.put("file", "String");
|
||||
typeMapping.put("map", "Map");
|
||||
typeMapping.put("array", "List");
|
||||
typeMapping.put("list", "List");
|
||||
// typeMapping.put("object", "Map");
|
||||
typeMapping.put("binary", "String");
|
||||
typeMapping.put("ByteArray", "String");
|
||||
typeMapping.put("UUID", "String");
|
||||
|
||||
cliOptions.add(new CliOption(CodegenConstants.INVOKER_PACKAGE, "The main namespace to use for all classes. e.g. Yay.Pets"));
|
||||
cliOptions.add(new CliOption("licenseHeader", "The license header to prepend to the top of all source files."));
|
||||
cliOptions.add(new CliOption(CodegenConstants.PACKAGE_NAME, "Elixir package name (convention: lowercase)."));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -153,6 +204,41 @@ public class ElixirClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
writer.write(modulized(fragment.execute()));
|
||||
}
|
||||
});
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.INVOKER_PACKAGE)) {
|
||||
setModuleName((String) additionalProperties.get(CodegenConstants.INVOKER_PACKAGE));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preprocessSwagger(Swagger swagger) {
|
||||
Info info = swagger.getInfo();
|
||||
if (moduleName == null) {
|
||||
if (info.getTitle() != null) {
|
||||
// default to the appName (from title field)
|
||||
setModuleName(modulized(escapeText(info.getTitle())));
|
||||
} else {
|
||||
setModuleName(defaultModuleName);
|
||||
}
|
||||
}
|
||||
additionalProperties.put("moduleName", moduleName);
|
||||
|
||||
if (!additionalProperties.containsKey(CodegenConstants.PACKAGE_NAME)) {
|
||||
additionalProperties.put(CodegenConstants.PACKAGE_NAME, underscored(moduleName));
|
||||
}
|
||||
|
||||
supportingFiles.add(new SupportingFile("connection.ex.mustache",
|
||||
sourceFolder(),
|
||||
"connection.ex"));
|
||||
|
||||
supportingFiles.add(new SupportingFile("request_builder.ex.mustache",
|
||||
sourceFolder(),
|
||||
"request_builder.ex"));
|
||||
|
||||
|
||||
supportingFiles.add(new SupportingFile("deserializer.ex.mustache",
|
||||
sourceFolder(),
|
||||
"deserializer.ex"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -160,14 +246,14 @@ public class ElixirClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
Map<String, Object> operations = (Map<String, Object>) super.postProcessOperations(objs).get("operations");
|
||||
List<CodegenOperation> os = (List<CodegenOperation>) operations.get("operation");
|
||||
List<ExtendedCodegenOperation> newOs = new ArrayList<ExtendedCodegenOperation>();
|
||||
Pattern pattern = Pattern.compile("(.*)\\{([^\\}]+)\\}(.*)");
|
||||
Pattern pattern = Pattern.compile("\\{([^\\}]+)\\}([^\\{]*)");
|
||||
for (CodegenOperation o : os) {
|
||||
ArrayList<String> pathTemplateNames = new ArrayList<String>();
|
||||
Matcher matcher = pattern.matcher(o.path);
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
while (matcher.find()) {
|
||||
String pathTemplateName = matcher.group(2);
|
||||
matcher.appendReplacement(buffer, "$1" + "#{" + underscore(pathTemplateName) + "}" + "$3");
|
||||
String pathTemplateName = matcher.group(1);
|
||||
matcher.appendReplacement(buffer, "#{" + underscore(pathTemplateName) + "}" + "$2");
|
||||
pathTemplateNames.add(pathTemplateName);
|
||||
}
|
||||
ExtendedCodegenOperation eco = new ExtendedCodegenOperation(o);
|
||||
@ -177,12 +263,29 @@ public class ElixirClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
eco.setReplacedPathName(buffer.toString());
|
||||
}
|
||||
eco.setPathTemplateNames(pathTemplateNames);
|
||||
|
||||
// detect multipart form types
|
||||
if (eco.hasConsumes == Boolean.TRUE) {
|
||||
Map<String, String> firstType = eco.consumes.get(0);
|
||||
if (firstType != null) {
|
||||
if ("multipart/form-data".equals(firstType.get("mediaType"))) {
|
||||
eco.isMultipart = Boolean.TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
newOs.add(eco);
|
||||
}
|
||||
operations.put("operation", newOs);
|
||||
return objs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenModel fromModel(String name, Model model, Map<String, Model> allDefinitions) {
|
||||
CodegenModel cm = super.fromModel(name, model, allDefinitions);
|
||||
return new ExtendedCodegenModel(cm);
|
||||
}
|
||||
|
||||
// We should use String.join if we can use Java8
|
||||
String join(CharSequence charSequence, Iterable<String> iterable) {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
@ -222,12 +325,20 @@ public class ElixirClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
return "_" + name; // add an underscore to the name
|
||||
}
|
||||
|
||||
private String sourceFolder() {
|
||||
ArrayList<String> underscoredWords = new ArrayList<String>();
|
||||
for (String word : moduleName.split("\\.")) {
|
||||
underscoredWords.add(underscore(word));
|
||||
}
|
||||
return "lib/" + join("/", underscoredWords);
|
||||
}
|
||||
|
||||
/**
|
||||
* Location to write model files. You can use the modelPackage() as defined when the class is
|
||||
* instantiated
|
||||
*/
|
||||
public String modelFileFolder() {
|
||||
return outputFolder + "/" + sourceFolder + "/" + underscored((String) additionalProperties.get("appName")) + "/" + "model";
|
||||
return outputFolder + "/" + sourceFolder() + "/" + "model";
|
||||
}
|
||||
|
||||
/**
|
||||
@ -236,7 +347,7 @@ public class ElixirClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
*/
|
||||
@Override
|
||||
public String apiFileFolder() {
|
||||
return outputFolder + "/" + sourceFolder + "/" + underscored((String) additionalProperties.get("appName")) + "/" + "api";
|
||||
return outputFolder + "/" + sourceFolder() + "/" + "api";
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -249,12 +360,22 @@ public class ElixirClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
|
||||
@Override
|
||||
public String toApiFilename(String name) {
|
||||
return snakeCase(name);
|
||||
return underscore(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelFilename(String name) {
|
||||
return snakeCase(name);
|
||||
return underscore(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toOperationId(String operationId) {
|
||||
// throw exception if method name is empty (should not occur as an auto-generated method name will be used)
|
||||
if (StringUtils.isEmpty(operationId)) {
|
||||
throw new RuntimeException("Empty method name (operationId) not allowed");
|
||||
}
|
||||
|
||||
return camelize(sanitizeName(operationId));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -374,6 +495,188 @@ public class ElixirClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
public void setReplacedPathName(String replacedPathName) {
|
||||
this.replacedPathName = replacedPathName;
|
||||
}
|
||||
|
||||
public String typespec() {
|
||||
StringBuilder sb = new StringBuilder("@spec ");
|
||||
sb.append(underscore(operationId));
|
||||
sb.append("(Tesla.Env.client, ");
|
||||
|
||||
for (CodegenParameter param : allParams) {
|
||||
if (param.required) {
|
||||
buildTypespec(param, sb);
|
||||
sb.append(", ");
|
||||
}
|
||||
}
|
||||
|
||||
sb.append("keyword()) :: {:ok, ");
|
||||
if (returnBaseType == null) {
|
||||
sb.append("nil");
|
||||
} else if (returnSimpleType) {
|
||||
if (!returnTypeIsPrimitive) {
|
||||
sb.append(moduleName);
|
||||
sb.append(".Model.");
|
||||
}
|
||||
sb.append(returnBaseType);
|
||||
sb.append(".t");
|
||||
} else if (returnContainer == null) {
|
||||
sb.append(returnBaseType);
|
||||
sb.append(".t");
|
||||
} else {
|
||||
if (returnContainer.equals("array")) {
|
||||
sb.append("list(");
|
||||
if (!returnTypeIsPrimitive) {
|
||||
sb.append(moduleName);
|
||||
sb.append(".Model.");
|
||||
}
|
||||
sb.append(returnBaseType);
|
||||
sb.append(".t)");
|
||||
} else if (returnContainer.equals("map")) {
|
||||
sb.append("map()");
|
||||
}
|
||||
}
|
||||
sb.append("} | {:error, Tesla.Env.t}");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private void buildTypespec(CodegenParameter param, StringBuilder sb) {
|
||||
if (param.dataType == null) {
|
||||
sb.append("nil");
|
||||
} else if (param.isListContainer) {
|
||||
// list(<subtype>)
|
||||
sb.append("list(");
|
||||
if (param.isBodyParam) {
|
||||
buildTypespec(param.items.items, sb);
|
||||
} else {
|
||||
buildTypespec(param.items, sb);
|
||||
}
|
||||
sb.append(")");
|
||||
} else if (param.isMapContainer) {
|
||||
// %{optional(String.t) => <subtype>}
|
||||
sb.append("%{optional(String.t) => ");
|
||||
buildTypespec(param.items, sb);
|
||||
sb.append("}");
|
||||
} else if (param.isPrimitiveType) {
|
||||
// <type>.t
|
||||
sb.append(param.dataType);
|
||||
sb.append(".t");
|
||||
} else if (param.isFile) {
|
||||
sb.append("String.t");
|
||||
} else {
|
||||
// <module>.Model.<type>.t
|
||||
sb.append(moduleName);
|
||||
sb.append(".Model.");
|
||||
sb.append(param.dataType);
|
||||
sb.append(".t");
|
||||
}
|
||||
}
|
||||
private void buildTypespec(CodegenProperty property, StringBuilder sb) {
|
||||
if (property.isListContainer) {
|
||||
sb.append("list(");
|
||||
buildTypespec(property.items, sb);
|
||||
sb.append(")");
|
||||
} else if (property.isMapContainer) {
|
||||
sb.append("%{optional(String.t) => ");
|
||||
buildTypespec(property.items, sb);
|
||||
sb.append("}");
|
||||
} else if (property.isPrimitiveType) {
|
||||
sb.append(property.baseType);
|
||||
sb.append(".t");
|
||||
} else {
|
||||
sb.append(moduleName);
|
||||
sb.append(".Model.");
|
||||
sb.append(property.baseType);
|
||||
sb.append(".t");
|
||||
}
|
||||
}
|
||||
|
||||
public String decodedStruct() {
|
||||
// Let Poison decode the entire response into a generic blob
|
||||
if (isMapContainer) {
|
||||
return "";
|
||||
}
|
||||
// Primitive return type, don't even try to decode
|
||||
if (returnBaseType == null || (returnSimpleType && returnTypeIsPrimitive)) {
|
||||
return "false";
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (isListContainer) {
|
||||
sb.append("[");
|
||||
}
|
||||
sb.append("%");
|
||||
sb.append(moduleName);
|
||||
sb.append(".Model.");
|
||||
sb.append(returnBaseType);
|
||||
sb.append("{}");
|
||||
if (isListContainer) {
|
||||
sb.append("]");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
class ExtendedCodegenModel extends CodegenModel {
|
||||
public boolean hasImports;
|
||||
public ExtendedCodegenModel(CodegenModel cm) {
|
||||
super();
|
||||
|
||||
// Copy all fields of CodegenModel
|
||||
this.parent = cm.parent;
|
||||
this.parentSchema = cm.parentSchema;
|
||||
this.parentModel = cm.parentModel;
|
||||
this.interfaceModels = cm.interfaceModels;
|
||||
this.children = cm.children;
|
||||
this.name = cm.name;
|
||||
this.classname = cm.classname;
|
||||
this.title = cm.title;
|
||||
this.description = cm.description;
|
||||
this.classVarName = cm.classVarName;
|
||||
this.modelJson = cm.modelJson;
|
||||
this.dataType = cm.dataType;
|
||||
this.xmlPrefix = cm.xmlPrefix;
|
||||
this.xmlNamespace = cm.xmlNamespace;
|
||||
this.xmlName = cm.xmlName;
|
||||
this.classFilename = cm.classFilename;
|
||||
this.unescapedDescription = cm.unescapedDescription;
|
||||
this.discriminator = cm.discriminator;
|
||||
this.defaultValue = cm.defaultValue;
|
||||
this.arrayModelType = cm.arrayModelType;
|
||||
this.isAlias = cm.isAlias;
|
||||
this.vars = cm.vars;
|
||||
this.requiredVars = cm.requiredVars;
|
||||
this.optionalVars = cm.optionalVars;
|
||||
this.readOnlyVars = cm.readOnlyVars;
|
||||
this.readWriteVars = cm.readWriteVars;
|
||||
this.allVars = cm.allVars;
|
||||
this.parentVars = cm.parentVars;
|
||||
this.allowableValues = cm.allowableValues;
|
||||
this.mandatory = cm.mandatory;
|
||||
this.allMandatory = cm.allMandatory;
|
||||
this.imports = cm.imports;
|
||||
this.hasVars = cm.hasVars;
|
||||
this.emptyVars = cm.emptyVars;
|
||||
this.hasMoreModels = cm.hasMoreModels;
|
||||
this.hasEnums = cm.hasEnums;
|
||||
this.isEnum = cm.isEnum;
|
||||
this.hasRequired = cm.hasRequired;
|
||||
this.hasOptional = cm.hasOptional;
|
||||
this.isArrayModel = cm.isArrayModel;
|
||||
this.hasChildren = cm.hasChildren;
|
||||
this.hasOnlyReadOnly = cm.hasOnlyReadOnly;
|
||||
this.externalDocs = cm.externalDocs;
|
||||
this.vendorExtensions = cm.vendorExtensions;
|
||||
this.additionalPropertiesType = cm.additionalPropertiesType;
|
||||
|
||||
this.hasImports = !this.imports.isEmpty();
|
||||
}
|
||||
|
||||
public boolean hasComplexVars() {
|
||||
for (CodegenProperty p : vars) {
|
||||
if (!p.isPrimitiveType) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -386,4 +689,8 @@ public class ElixirClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
// no need to escape as Elixir does not support multi-line comments
|
||||
return input;
|
||||
}
|
||||
|
||||
public void setModuleName(String moduleName) {
|
||||
this.moduleName = moduleName;
|
||||
}
|
||||
}
|
||||
|
@ -1,18 +1,18 @@
|
||||
# {{#modulized}}{{appName}}{{/modulized}}
|
||||
# {{moduleName}}
|
||||
|
||||
**TODO: Add description**
|
||||
{{appDescription}}
|
||||
|
||||
## Installation
|
||||
|
||||
If [available in Hex](https://hex.pm/docs/publish), the package can be installed
|
||||
by adding `{{#underscored}}{{appName}}{{/underscored}}` to your list of dependencies in `mix.exs`:
|
||||
by adding `{{#underscored}}{{packageName}}{{/underscored}}` to your list of dependencies in `mix.exs`:
|
||||
|
||||
```elixir
|
||||
def deps do
|
||||
[{:{{#underscored}}{{appName}}{{/underscored}}, "~> 0.1.0"}]
|
||||
[{:{{#underscored}}{{packageName}}{{/underscored}}, "~> 0.1.0"}]
|
||||
end
|
||||
```
|
||||
|
||||
Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
|
||||
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
|
||||
be found at [https://hexdocs.pm/{{#underscored}}{{appName}}{{/underscored}}](https://hexdocs.pm/{{#underscored}}{{appName}}{{/underscored}}).
|
||||
be found at [https://hexdocs.pm/{{#underscored}}{{packageName}}{{/underscored}}](https://hexdocs.pm/{{#underscored}}{{packageName}}{{/underscored}}).
|
||||
|
@ -1,35 +1,59 @@
|
||||
defmodule {{#modulized}}{{appName}}{{/modulized}}.Api.{{classname}} do
|
||||
{{>licenseInfo}}
|
||||
defmodule {{moduleName}}.Api.{{classname}} do
|
||||
@moduledoc """
|
||||
Documentation for {{#modulized}}{{appName}}{{/modulized}}.Api.{{classname}}.
|
||||
API calls for all endpoints tagged `{{baseName}}`.
|
||||
"""
|
||||
|
||||
use Tesla
|
||||
alias {{moduleName}}.Connection
|
||||
import {{moduleName}}.RequestBuilder
|
||||
|
||||
plug Tesla.Middleware.BaseUrl, "{{{basePath}}}"
|
||||
plug Tesla.Middleware.JSON
|
||||
{{#operations}}
|
||||
{{#operation}}
|
||||
{{#operation}}
|
||||
|
||||
@doc """
|
||||
{{#summary}}
|
||||
{{summary}}
|
||||
{{^notes.isEmpty}}
|
||||
|
||||
{{/summary}}
|
||||
{{#notes}}
|
||||
{{notes}}
|
||||
{{/notes.isEmpty}}
|
||||
"""
|
||||
def {{#underscored}}{{operationId}}{{/underscored}}({{#allParams}}{{^-first}}, {{/-first}}{{#underscored}}{{paramName}}{{/underscored}}{{/allParams}}) do
|
||||
method = [method: :{{#underscored}}{{httpMethod}}{{/underscored}}]
|
||||
url = [url: "{{replacedPathName}}"]
|
||||
query_params = [{{^queryParams.isEmpty}}query: [{{#queryParams}}{{^-first}}, {{/-first}}{:"{{baseName}}", {{#underscored}}{{paramName}}{{/underscored}}}{{/queryParams}}]{{/queryParams.isEmpty}}]
|
||||
header_params = [{{^headerParams.isEmpty}}header: [{{#headerParams}}{{^-first}}, {{/-first}}{:"{{baseName}}", {{#underscored}}{{paramName}}{{/underscored}}}{{/headerParams}}]{{/headerParams.isEmpty}}]
|
||||
body_params = [{{^bodyParams.isEmpty}}body: {{#bodyParams}}{{#underscored}}{{paramName}}{{/underscored}}{{/bodyParams}}{{/bodyParams.isEmpty}}]
|
||||
form_params = [{{^formParams.isEmpty}}body: Enum.map_join([{{#formParams}}{{^-first}}, {{/-first}}{:"{{baseName}}", {{#underscored}}{{paramName}}{{/underscored}}}{{/formParams}}], "&", &("#{elem(&1, 0)}=#{elem(&1, 1)}")){{/formParams.isEmpty}}]
|
||||
params = query_params ++ header_params ++ body_params ++ form_params
|
||||
opts = []
|
||||
options = method ++ url ++ params ++ opts
|
||||
{{/notes}}
|
||||
|
||||
request(options)
|
||||
## Parameters
|
||||
|
||||
- connection ({{moduleName}}.Connection): Connection to server
|
||||
{{#allParams}}{{#required}} - {{#underscored}}{{paramName}}{{/underscored}} ({{dataType}}): {{description}}
|
||||
{{/required}}{{/allParams}} - opts (KeywordList): [optional] Optional parameters
|
||||
{{#allParams}}{{^required}} - {{#underscored}}:{{paramName}}{{/underscored}} ({{dataType}}): {{description}}
|
||||
{{/required}}{{/allParams}}
|
||||
## Returns
|
||||
|
||||
{:ok, {{#isListContainer}}[%{{returnBaseType}}{}, ...]{{/isListContainer}}{{#isMapContainer}}%{}{{/isMapContainer}}{{^returnType}}%{}{{/returnType}}{{#returnSimpleType}}%{{#returnType}}{{#isMapContainer}}{{/isMapContainer}}{{moduleName}}.Model.{{{returnType}}}{{/returnType}}{}{{/returnSimpleType}}} on success
|
||||
{:error, info} on failure
|
||||
"""
|
||||
{{typespec}}
|
||||
def {{#underscored}}{{operationId}}{{/underscored}}(connection, {{#allParams}}{{#required}}{{#underscored}}{{paramName}}{{/underscored}}, {{/required}}{{/allParams}}{{^hasOptionalParams}}_{{/hasOptionalParams}}opts \\ []) do
|
||||
{{#hasOptionalParams}}
|
||||
optional_params = %{
|
||||
{{#allParams}}{{^required}}{{^isPathParam}}:"{{baseName}}" => {{#isBodyParam}}:body{{/isBodyParam}}{{#isFormParam}}:form{{/isFormParam}}{{#isQueryParam}}:query{{/isQueryParam}}{{#isHeaderParam}}:headers{{/isHeaderParam}}{{/isPathParam}}{{#hasMore}},
|
||||
{{/hasMore}}{{/required}}{{/allParams}}
|
||||
}
|
||||
{{/hasOptionalParams}}
|
||||
%{}
|
||||
|> method(:{{#underscored}}{{httpMethod}}{{/underscored}})
|
||||
|> url("{{replacedPathName}}")
|
||||
{{#allParams}}
|
||||
{{#required}}
|
||||
{{^isPathParam}} |> add_param({{#isBodyParam}}:body{{/isBodyParam}}{{#isFormParam}}{{#isMultipart}}{{#isFile}}:file{{/isFile}}{{^isFile}}:form{{/isFile}}{{/isMultipart}}{{^isMultipart}}:form{{/isMultipart}}{{/isFormParam}}{{#isQueryParam}}:query{{/isQueryParam}}{{#isHeaderParam}}:headers{{/isHeaderParam}}, :"{{baseName}}", {{#underscored}}{{paramName}}{{/underscored}})
|
||||
{{/isPathParam}}
|
||||
{{/required}}
|
||||
{{/allParams}}
|
||||
{{#hasOptionalParams}}
|
||||
|> add_optional_params(optional_params, opts)
|
||||
{{/hasOptionalParams}}
|
||||
|> Enum.into([])
|
||||
|> (&Connection.request(connection, &1)).()
|
||||
|> decode({{decodedStruct}})
|
||||
end
|
||||
{{/operation}}
|
||||
{{/operation}}
|
||||
{{/operations}}
|
||||
end
|
||||
|
@ -0,0 +1,92 @@
|
||||
{{>licenseInfo}}
|
||||
defmodule {{moduleName}}.Connection do
|
||||
@moduledoc """
|
||||
Handle Tesla connections for {{moduleName}}.
|
||||
"""
|
||||
|
||||
use Tesla
|
||||
|
||||
# Add any middleware here (authentication)
|
||||
plug Tesla.Middleware.BaseUrl, "{{{basePath}}}"
|
||||
plug Tesla.Middleware.Headers, %{"User-Agent" => "Elixir"}
|
||||
plug Tesla.Middleware.EncodeJson
|
||||
|
||||
{{#hasAuthMethods}}
|
||||
{{#authMethods}}
|
||||
{{#isOAuth}}
|
||||
@scopes [
|
||||
{{#scopes}}
|
||||
"{{scope}}"{{#hasMore}},{{/hasMore}} {{#description}}# {{description}}{{/description}}
|
||||
{{/scopes}}
|
||||
]
|
||||
|
||||
@doc """
|
||||
Configure a client connection using a provided OAuth2 token as a Bearer token
|
||||
|
||||
## Parameters
|
||||
|
||||
- token (String): Bearer token
|
||||
|
||||
## Returns
|
||||
|
||||
Tesla.Env.client
|
||||
"""
|
||||
@spec new(String.t) :: Tesla.Env.client
|
||||
def new(token) when is_binary(token) do
|
||||
Tesla.build_client([
|
||||
{Tesla.Middleware.Headers, %{"Authorization" => "Bearer #{token}"}}
|
||||
])
|
||||
end
|
||||
|
||||
@doc """
|
||||
Configure a client connection using a function which yields a Bearer token.
|
||||
|
||||
## Parameters
|
||||
|
||||
- token_fetcher (function arity of 1): Callback which provides an OAuth2 token
|
||||
given a list of scopes
|
||||
|
||||
## Returns
|
||||
|
||||
Tesla.Env.client
|
||||
"""
|
||||
@spec new(((list(String.t)) -> String.t)) :: Tesla.Env.client
|
||||
def new(token_fetcher) when is_function(token_fetcher) do
|
||||
token_fetcher.(@scopes)
|
||||
|> new
|
||||
end
|
||||
{{/isOAuth}}
|
||||
{{#isBasic}}
|
||||
@doc """
|
||||
Configure an client connection using Basic authentication.
|
||||
|
||||
## Parameters
|
||||
|
||||
- username (String): Username used for authentication
|
||||
- password (String): Password used for authentication
|
||||
|
||||
# Returns
|
||||
|
||||
Tesla.Env.client
|
||||
"""
|
||||
@spec new(String.t, String.t) :: Tesla.Env.client
|
||||
def new(username, password) do
|
||||
Tesla.build_client([
|
||||
{Tesla.Middleware.BasicAuth, %{username: username, password: password}}
|
||||
])
|
||||
end
|
||||
{{/isBasic}}
|
||||
{{/authMethods}}
|
||||
{{/hasAuthMethods}}
|
||||
@doc """
|
||||
Configure an authless client connection
|
||||
|
||||
# Returns
|
||||
|
||||
Tesla.Env.client
|
||||
"""
|
||||
@spec new() :: Tesla.Env.client
|
||||
def new do
|
||||
Tesla.build_client([])
|
||||
end
|
||||
end
|
@ -0,0 +1,31 @@
|
||||
{{>licenseInfo}}
|
||||
defmodule {{moduleName}}.Deserializer do
|
||||
@moduledoc """
|
||||
Helper functions for deserializing responses into models
|
||||
"""
|
||||
|
||||
@doc """
|
||||
Update the provided model with a deserialization of a nested value
|
||||
"""
|
||||
@spec deserialize(struct(), :atom, :atom, struct(), keyword()) :: struct()
|
||||
def deserialize(model, field, :list, mod, options) do
|
||||
model
|
||||
|> Map.update!(field, &(Poison.Decode.decode(&1, Keyword.merge(options, [as: [struct(mod)]]))))
|
||||
end
|
||||
def deserialize(model, field, :struct, mod, options) do
|
||||
model
|
||||
|> Map.update!(field, &(Poison.Decode.decode(&1, Keyword.merge(options, [as: struct(mod)]))))
|
||||
end
|
||||
def deserialize(model, field, :map, mod, options) do
|
||||
model
|
||||
|> Map.update!(field, &(Map.new(&1, fn {key, val} -> {key, Poison.Decode.decode(val, Keyword.merge(options, [as: struct(mod)]))} end)))
|
||||
end
|
||||
def deserialize(model, field, :date, _, _options) do
|
||||
case DateTime.from_iso8601(Map.get(model, field)) do
|
||||
{:ok, datetime} ->
|
||||
Map.put(model, field, datetime)
|
||||
_ ->
|
||||
model
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,20 @@
|
||||
# The directory Mix will write compiled artifacts to.
|
||||
/_build
|
||||
|
||||
# If you run "mix test --cover", coverage assets end up here.
|
||||
/cover
|
||||
|
||||
# The directory Mix downloads your dependencies sources to.
|
||||
/deps
|
||||
|
||||
# Where 3rd-party dependencies like ExDoc output generated docs.
|
||||
/doc
|
||||
|
||||
# Ignore .fetch files in case you like to edit your project deps locally.
|
||||
/.fetch
|
||||
|
||||
# If the VM crashes, it generates a dump, let's ignore it too.
|
||||
erl_crash.dump
|
||||
|
||||
# Also ignore archive artifacts (built via "mix archive.build").
|
||||
*.ez
|
@ -0,0 +1,6 @@
|
||||
{{#licenseHeader}}{{licenseHeader}}
|
||||
|
||||
{{/licenseHeader}}
|
||||
# NOTE: This class is auto generated by the swagger code generator program.
|
||||
# https://github.com/swagger-api/swagger-codegen.git
|
||||
# Do not edit the class manually.
|
@ -1,8 +1,8 @@
|
||||
defmodule {{#modulized}}{{appName}}{{/modulized}}.Mixfile do
|
||||
defmodule {{moduleName}}.Mixfile do
|
||||
use Mix.Project
|
||||
|
||||
def project do
|
||||
[app: :{{#underscored}}{{appName}}{{/underscored}},
|
||||
[app: :{{#underscored}}{{packageName}}{{/underscored}},
|
||||
version: "0.1.0",
|
||||
elixir: "~> {{supportedElixirVersion}}",
|
||||
build_embedded: Mix.env == :prod,
|
||||
|
@ -0,0 +1,32 @@
|
||||
{{>licenseInfo}}
|
||||
{{#models}}{{#model}}defmodule {{moduleName}}.Model.{{classname}} do
|
||||
@moduledoc """
|
||||
{{description}}
|
||||
"""
|
||||
|
||||
@derive [Poison.Encoder]
|
||||
defstruct [
|
||||
{{#vars}}:"{{baseName}}"{{#hasMore}},
|
||||
{{/hasMore}}{{/vars}}
|
||||
]
|
||||
end
|
||||
|
||||
defimpl Poison.Decoder, for: {{moduleName}}.Model.{{classname}} do
|
||||
{{#hasComplexVars}}
|
||||
import {{moduleName}}.Deserializer
|
||||
def decode(value, options) do
|
||||
value
|
||||
{{#vars}}
|
||||
{{^isPrimitiveType}}
|
||||
{{#datatype}}|> deserialize(:"{{baseName}}", {{#isListContainer}}:list, {{moduleName}}.Model.{{items.datatype}}{{/isListContainer}}{{#isMapContainer}}:map, {{moduleName}}.Model.{{items.datatype}}{{/isMapContainer}}{{#isDate}}:date, nil{{/isDate}}{{#isDateTime}}:date, nil{{/isDateTime}}{{^isDate}}{{^isDateTime}}{{^isMapContainer}}{{^isListContainer}}:struct, {{moduleName}}.Model.{{datatype}}{{/isListContainer}}{{/isMapContainer}}{{/isDateTime}}{{/isDate}}, options)
|
||||
{{/datatype}}
|
||||
{{/isPrimitiveType}}
|
||||
{{/vars}}
|
||||
{{/hasComplexVars}}
|
||||
{{^hasComplexVars}}
|
||||
def decode(value, _options) do
|
||||
value
|
||||
{{/hasComplexVars}}
|
||||
end
|
||||
end
|
||||
{{/model}}{{/models}}
|
@ -0,0 +1,127 @@
|
||||
{{>licenseInfo}}
|
||||
defmodule {{moduleName}}.RequestBuilder do
|
||||
@moduledoc """
|
||||
Helper functions for building Tesla requests
|
||||
"""
|
||||
|
||||
@doc """
|
||||
Specify the request method when building a request
|
||||
|
||||
## Parameters
|
||||
|
||||
- request (Map) - Collected request options
|
||||
- m (String) - Request method
|
||||
|
||||
## Returns
|
||||
|
||||
Map
|
||||
"""
|
||||
@spec method(map(), String.t) :: map()
|
||||
def method(request, m) do
|
||||
Map.put_new(request, :method, m)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Specify the request method when building a request
|
||||
|
||||
## Parameters
|
||||
|
||||
- request (Map) - Collected request options
|
||||
- u (String) - Request URL
|
||||
|
||||
## Returns
|
||||
|
||||
Map
|
||||
"""
|
||||
@spec url(map(), String.t) :: map()
|
||||
def url(request, u) do
|
||||
Map.put_new(request, :url, u)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Add optional parameters to the request
|
||||
|
||||
## Parameters
|
||||
|
||||
- request (Map) - Collected request options
|
||||
- definitions (Map) - Map of parameter name to parameter location.
|
||||
- options (KeywordList) - The provided optional parameters
|
||||
|
||||
## Returns
|
||||
|
||||
Map
|
||||
"""
|
||||
@spec add_optional_params(map(), %{optional(:atom) => :atom}, keyword()) :: map()
|
||||
def add_optional_params(request, _, []), do: request
|
||||
def add_optional_params(request, definitions, [{key, value} | tail]) do
|
||||
case definitions do
|
||||
%{^key => location} ->
|
||||
request
|
||||
|> add_param(location, key, value)
|
||||
|> add_optional_params(definitions, tail)
|
||||
_ ->
|
||||
add_optional_params(request, definitions, tail)
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
Add optional parameters to the request
|
||||
|
||||
## Parameters
|
||||
|
||||
- request (Map) - Collected request options
|
||||
- location (atom) - Where to put the parameter
|
||||
- key (atom) - The name of the parameter
|
||||
- value (any) - The value of the parameter
|
||||
|
||||
## Returns
|
||||
|
||||
Map
|
||||
"""
|
||||
@spec add_param(map(), :atom, :atom, any()) :: map()
|
||||
def add_param(request, :body, :body, value), do: Map.put(request, :body, value)
|
||||
def add_param(request, :body, key, value) do
|
||||
request
|
||||
|> Map.put_new_lazy(:body, &Tesla.Multipart.new/0)
|
||||
|> Map.update!(:body, &(Tesla.Multipart.add_field(&1, key, Poison.encode!(value), headers: [{:"Content-Type", "application/json"}])))
|
||||
end
|
||||
def add_param(request, :file, name, path) do
|
||||
request
|
||||
|> Map.put_new_lazy(:body, &Tesla.Multipart.new/0)
|
||||
|> Map.update!(:body, &(Tesla.Multipart.add_file(&1, path, name: name)))
|
||||
end
|
||||
def add_param(request, :form, name, value) do
|
||||
request
|
||||
|> Map.update(:body, %{name => value}, &(Map.put(&1, name, value)))
|
||||
end
|
||||
def add_param(request, location, key, value) do
|
||||
Map.update(request, location, [{key, value}], &(&1 ++ [{key, value}]))
|
||||
end
|
||||
|
||||
@doc """
|
||||
Handle the response for a Tesla request
|
||||
|
||||
## Parameters
|
||||
|
||||
- env (Tesla.Env) - The response object
|
||||
- struct - The shape of the struct to deserialize into
|
||||
|
||||
## Returns
|
||||
|
||||
{:ok, struct} on success
|
||||
{:error, info} on failure
|
||||
"""
|
||||
@spec decode(Tesla.Env.t) :: {:ok, struct()} | {:error, Tesla.Env.t}
|
||||
def decode(%Tesla.Env{status: 200, body: body}), do: Poison.decode(body)
|
||||
def decode(response) do
|
||||
{:error, response}
|
||||
end
|
||||
@spec decode(Tesla.Env.t, struct()) :: {:ok, struct()} | {:error, Tesla.Env.t}
|
||||
def decode(%Tesla.Env{status: 200} = env, false), do: {:ok, env}
|
||||
def decode(%Tesla.Env{status: 200, body: body}, struct) do
|
||||
Poison.decode(body, as: struct)
|
||||
end
|
||||
def decode(response, _struct) do
|
||||
{:error, response}
|
||||
end
|
||||
end
|
@ -4,6 +4,7 @@ import io.swagger.codegen.AbstractOptionsTest;
|
||||
import io.swagger.codegen.CodegenConfig;
|
||||
import io.swagger.codegen.languages.ElixirClientCodegen;
|
||||
import io.swagger.codegen.options.ElixirClientOptionsProvider;
|
||||
import io.swagger.codegen.options.PhpClientOptionsProvider;
|
||||
import mockit.Expectations;
|
||||
import mockit.Tested;
|
||||
|
||||
@ -26,6 +27,8 @@ public class ElixirClientOptionsTest extends AbstractOptionsTest {
|
||||
protected void setExpectations() {
|
||||
new Expectations(clientCodegen) {{
|
||||
// TODO
|
||||
clientCodegen.setModuleName(ElixirClientOptionsProvider.INVOKER_PACKAGE_VALUE);
|
||||
times = 1;
|
||||
}};
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import io.swagger.codegen.CodegenConstants;
|
||||
import java.util.Map;
|
||||
|
||||
public class ElixirClientOptionsProvider implements OptionsProvider {
|
||||
public static final String INVOKER_PACKAGE_VALUE = "Yay.Pets";
|
||||
|
||||
@Override
|
||||
public String getLanguage() {
|
||||
@ -19,6 +20,9 @@ public class ElixirClientOptionsProvider implements OptionsProvider {
|
||||
.put(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG, "false")
|
||||
.put(CodegenConstants.ENSURE_UNIQUE_PARAMS, "false")
|
||||
.put(CodegenConstants.ALLOW_UNICODE_IDENTIFIERS, "false")
|
||||
.put(CodegenConstants.INVOKER_PACKAGE, "Yay.Pets")
|
||||
.put("licenseHeader", "# Copyright 2017 Me\n#\n# Licensed under the Apache License")
|
||||
.put(CodegenConstants.PACKAGE_NAME, "yay_pets")
|
||||
.build();
|
||||
}
|
||||
|
||||
|
20
samples/client/petstore/elixir/.gitignore
vendored
Normal file
20
samples/client/petstore/elixir/.gitignore
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
# The directory Mix will write compiled artifacts to.
|
||||
/_build
|
||||
|
||||
# If you run "mix test --cover", coverage assets end up here.
|
||||
/cover
|
||||
|
||||
# The directory Mix downloads your dependencies sources to.
|
||||
/deps
|
||||
|
||||
# Where 3rd-party dependencies like ExDoc output generated docs.
|
||||
/doc
|
||||
|
||||
# Ignore .fetch files in case you like to edit your project deps locally.
|
||||
/.fetch
|
||||
|
||||
# If the VM crashes, it generates a dump, let's ignore it too.
|
||||
erl_crash.dump
|
||||
|
||||
# Also ignore archive artifacts (built via "mix archive.build").
|
||||
*.ez
|
@ -1,6 +1,6 @@
|
||||
# SwaggerPetstore
|
||||
|
||||
**TODO: Add description**
|
||||
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
|
||||
## Installation
|
||||
|
||||
|
@ -0,0 +1,39 @@
|
||||
# NOTE: This class is auto generated by the swagger code generator program.
|
||||
# https://github.com/swagger-api/swagger-codegen.git
|
||||
# Do not edit the class manually.
|
||||
|
||||
defmodule SwaggerPetstore.Api.AnotherFake do
|
||||
@moduledoc """
|
||||
API calls for all endpoints tagged `AnotherFake`.
|
||||
"""
|
||||
|
||||
alias SwaggerPetstore.Connection
|
||||
import SwaggerPetstore.RequestBuilder
|
||||
|
||||
|
||||
@doc """
|
||||
To test special tags
|
||||
To test special tags
|
||||
|
||||
## Parameters
|
||||
|
||||
- connection (SwaggerPetstore.Connection): Connection to server
|
||||
- body (Client): client model
|
||||
- opts (KeywordList): [optional] Optional parameters
|
||||
|
||||
## Returns
|
||||
|
||||
{:ok, %SwaggerPetstore.Model.Client{}} on success
|
||||
{:error, info} on failure
|
||||
"""
|
||||
@spec test_special_tags(Tesla.Env.client, SwaggerPetstore.Model.Client.t, keyword()) :: {:ok, SwaggerPetstore.Model.Client.t} | {:error, Tesla.Env.t}
|
||||
def test_special_tags(connection, body, _opts \\ []) do
|
||||
%{}
|
||||
|> method(:patch)
|
||||
|> url("/another-fake/dummy")
|
||||
|> add_param(:body, :"body", body)
|
||||
|> Enum.into([])
|
||||
|> (&Connection.request(connection, &1)).()
|
||||
|> decode(%SwaggerPetstore.Model.Client{})
|
||||
end
|
||||
end
|
@ -1,144 +1,278 @@
|
||||
# NOTE: This class is auto generated by the swagger code generator program.
|
||||
# https://github.com/swagger-api/swagger-codegen.git
|
||||
# Do not edit the class manually.
|
||||
|
||||
defmodule SwaggerPetstore.Api.Fake do
|
||||
@moduledoc """
|
||||
Documentation for SwaggerPetstore.Api.Fake.
|
||||
API calls for all endpoints tagged `Fake`.
|
||||
"""
|
||||
|
||||
use Tesla
|
||||
alias SwaggerPetstore.Connection
|
||||
import SwaggerPetstore.RequestBuilder
|
||||
|
||||
plug Tesla.Middleware.BaseUrl, "http://petstore.swagger.io:80/v2"
|
||||
plug Tesla.Middleware.JSON
|
||||
|
||||
@doc """
|
||||
|
||||
|
||||
Test serialization of outer boolean types
|
||||
"""
|
||||
def fake_outer_boolean_serialize(body) do
|
||||
method = [method: :post]
|
||||
url = [url: "/fake/outer/boolean"]
|
||||
query_params = []
|
||||
header_params = []
|
||||
body_params = [body: body]
|
||||
form_params = []
|
||||
params = query_params ++ header_params ++ body_params ++ form_params
|
||||
opts = []
|
||||
options = method ++ url ++ params ++ opts
|
||||
|
||||
request(options)
|
||||
## Parameters
|
||||
|
||||
- connection (SwaggerPetstore.Connection): Connection to server
|
||||
- opts (KeywordList): [optional] Optional parameters
|
||||
- :body (OuterBoolean): Input boolean as post body
|
||||
|
||||
## Returns
|
||||
|
||||
{:ok, %SwaggerPetstore.Model.OuterBoolean{}} on success
|
||||
{:error, info} on failure
|
||||
"""
|
||||
@spec fake_outer_boolean_serialize(Tesla.Env.client, keyword()) :: {:ok, SwaggerPetstore.Model.OuterBoolean.t} | {:error, Tesla.Env.t}
|
||||
def fake_outer_boolean_serialize(connection, opts \\ []) do
|
||||
optional_params = %{
|
||||
:"body" => :body
|
||||
}
|
||||
%{}
|
||||
|> method(:post)
|
||||
|> url("/fake/outer/boolean")
|
||||
|> add_optional_params(optional_params, opts)
|
||||
|> Enum.into([])
|
||||
|> (&Connection.request(connection, &1)).()
|
||||
|> decode(%SwaggerPetstore.Model.OuterBoolean{})
|
||||
end
|
||||
|
||||
@doc """
|
||||
|
||||
|
||||
Test serialization of object with outer number type
|
||||
"""
|
||||
def fake_outer_composite_serialize(body) do
|
||||
method = [method: :post]
|
||||
url = [url: "/fake/outer/composite"]
|
||||
query_params = []
|
||||
header_params = []
|
||||
body_params = [body: body]
|
||||
form_params = []
|
||||
params = query_params ++ header_params ++ body_params ++ form_params
|
||||
opts = []
|
||||
options = method ++ url ++ params ++ opts
|
||||
|
||||
request(options)
|
||||
## Parameters
|
||||
|
||||
- connection (SwaggerPetstore.Connection): Connection to server
|
||||
- opts (KeywordList): [optional] Optional parameters
|
||||
- :body (OuterComposite): Input composite as post body
|
||||
|
||||
## Returns
|
||||
|
||||
{:ok, %SwaggerPetstore.Model.OuterComposite{}} on success
|
||||
{:error, info} on failure
|
||||
"""
|
||||
@spec fake_outer_composite_serialize(Tesla.Env.client, keyword()) :: {:ok, SwaggerPetstore.Model.OuterComposite.t} | {:error, Tesla.Env.t}
|
||||
def fake_outer_composite_serialize(connection, opts \\ []) do
|
||||
optional_params = %{
|
||||
:"body" => :body
|
||||
}
|
||||
%{}
|
||||
|> method(:post)
|
||||
|> url("/fake/outer/composite")
|
||||
|> add_optional_params(optional_params, opts)
|
||||
|> Enum.into([])
|
||||
|> (&Connection.request(connection, &1)).()
|
||||
|> decode(%SwaggerPetstore.Model.OuterComposite{})
|
||||
end
|
||||
|
||||
@doc """
|
||||
|
||||
|
||||
Test serialization of outer number types
|
||||
"""
|
||||
def fake_outer_number_serialize(body) do
|
||||
method = [method: :post]
|
||||
url = [url: "/fake/outer/number"]
|
||||
query_params = []
|
||||
header_params = []
|
||||
body_params = [body: body]
|
||||
form_params = []
|
||||
params = query_params ++ header_params ++ body_params ++ form_params
|
||||
opts = []
|
||||
options = method ++ url ++ params ++ opts
|
||||
|
||||
request(options)
|
||||
## Parameters
|
||||
|
||||
- connection (SwaggerPetstore.Connection): Connection to server
|
||||
- opts (KeywordList): [optional] Optional parameters
|
||||
- :body (OuterNumber): Input number as post body
|
||||
|
||||
## Returns
|
||||
|
||||
{:ok, %SwaggerPetstore.Model.OuterNumber{}} on success
|
||||
{:error, info} on failure
|
||||
"""
|
||||
@spec fake_outer_number_serialize(Tesla.Env.client, keyword()) :: {:ok, SwaggerPetstore.Model.OuterNumber.t} | {:error, Tesla.Env.t}
|
||||
def fake_outer_number_serialize(connection, opts \\ []) do
|
||||
optional_params = %{
|
||||
:"body" => :body
|
||||
}
|
||||
%{}
|
||||
|> method(:post)
|
||||
|> url("/fake/outer/number")
|
||||
|> add_optional_params(optional_params, opts)
|
||||
|> Enum.into([])
|
||||
|> (&Connection.request(connection, &1)).()
|
||||
|> decode(%SwaggerPetstore.Model.OuterNumber{})
|
||||
end
|
||||
|
||||
@doc """
|
||||
Test serialization of outer string types
|
||||
|
||||
## Parameters
|
||||
|
||||
- connection (SwaggerPetstore.Connection): Connection to server
|
||||
- opts (KeywordList): [optional] Optional parameters
|
||||
- :body (OuterString): Input string as post body
|
||||
|
||||
## Returns
|
||||
|
||||
{:ok, %SwaggerPetstore.Model.OuterString{}} on success
|
||||
{:error, info} on failure
|
||||
"""
|
||||
@spec fake_outer_string_serialize(Tesla.Env.client, keyword()) :: {:ok, SwaggerPetstore.Model.OuterString.t} | {:error, Tesla.Env.t}
|
||||
def fake_outer_string_serialize(connection, opts \\ []) do
|
||||
optional_params = %{
|
||||
:"body" => :body
|
||||
}
|
||||
%{}
|
||||
|> method(:post)
|
||||
|> url("/fake/outer/string")
|
||||
|> add_optional_params(optional_params, opts)
|
||||
|> Enum.into([])
|
||||
|> (&Connection.request(connection, &1)).()
|
||||
|> decode(%SwaggerPetstore.Model.OuterString{})
|
||||
end
|
||||
|
||||
@doc """
|
||||
To test \"client\" model
|
||||
To test \"client\" model
|
||||
|
||||
## Parameters
|
||||
|
||||
- connection (SwaggerPetstore.Connection): Connection to server
|
||||
- body (Client): client model
|
||||
- opts (KeywordList): [optional] Optional parameters
|
||||
|
||||
## Returns
|
||||
|
||||
{:ok, %SwaggerPetstore.Model.Client{}} on success
|
||||
{:error, info} on failure
|
||||
"""
|
||||
@spec test_client_model(Tesla.Env.client, SwaggerPetstore.Model.Client.t, keyword()) :: {:ok, SwaggerPetstore.Model.Client.t} | {:error, Tesla.Env.t}
|
||||
def test_client_model(connection, body, _opts \\ []) do
|
||||
%{}
|
||||
|> method(:patch)
|
||||
|> url("/fake")
|
||||
|> add_param(:body, :"body", body)
|
||||
|> Enum.into([])
|
||||
|> (&Connection.request(connection, &1)).()
|
||||
|> decode(%SwaggerPetstore.Model.Client{})
|
||||
end
|
||||
|
||||
@doc """
|
||||
Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
|
||||
Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
|
||||
|
||||
## Parameters
|
||||
|
||||
- connection (SwaggerPetstore.Connection): Connection to server
|
||||
- number (Float): None
|
||||
- double (Float): None
|
||||
- pattern_without_delimiter (String): None
|
||||
- byte (String): None
|
||||
- opts (KeywordList): [optional] Optional parameters
|
||||
- :integer (Integer): None
|
||||
- :int32 (Integer): None
|
||||
- :int64 (Integer): None
|
||||
- :float (Float): None
|
||||
- :string (String): None
|
||||
- :binary (String): None
|
||||
- :date (DateTime): None
|
||||
- :date_time (DateTime): None
|
||||
- :password (String): None
|
||||
- :callback (String): None
|
||||
|
||||
## Returns
|
||||
|
||||
{:ok, %{}} on success
|
||||
{:error, info} on failure
|
||||
"""
|
||||
@spec test_endpoint_parameters(Tesla.Env.client, Float.t, Float.t, String.t, String.t, keyword()) :: {:ok, nil} | {:error, Tesla.Env.t}
|
||||
def test_endpoint_parameters(connection, number, double, pattern_without_delimiter, byte, opts \\ []) do
|
||||
optional_params = %{
|
||||
:"integer" => :form,
|
||||
:"int32" => :form,
|
||||
:"int64" => :form,
|
||||
:"float" => :form,
|
||||
:"string" => :form,
|
||||
:"binary" => :form,
|
||||
:"date" => :form,
|
||||
:"dateTime" => :form,
|
||||
:"password" => :form,
|
||||
:"callback" => :form
|
||||
}
|
||||
%{}
|
||||
|> method(:post)
|
||||
|> url("/fake")
|
||||
|> add_param(:form, :"number", number)
|
||||
|> add_param(:form, :"double", double)
|
||||
|> add_param(:form, :"pattern_without_delimiter", pattern_without_delimiter)
|
||||
|> add_param(:form, :"byte", byte)
|
||||
|> add_optional_params(optional_params, opts)
|
||||
|> Enum.into([])
|
||||
|> (&Connection.request(connection, &1)).()
|
||||
|> decode(false)
|
||||
end
|
||||
|
||||
@doc """
|
||||
To test enum parameters
|
||||
To test enum parameters
|
||||
|
||||
## Parameters
|
||||
|
||||
- connection (SwaggerPetstore.Connection): Connection to server
|
||||
- opts (KeywordList): [optional] Optional parameters
|
||||
- :enum_form_string_array (List[String]): Form parameter enum test (string array)
|
||||
- :enum_form_string (String): Form parameter enum test (string)
|
||||
- :enum_header_string_array (List[String]): Header parameter enum test (string array)
|
||||
- :enum_header_string (String): Header parameter enum test (string)
|
||||
- :enum_query_string_array (List[String]): Query parameter enum test (string array)
|
||||
- :enum_query_string (String): Query parameter enum test (string)
|
||||
- :enum_query_integer (Integer): Query parameter enum test (double)
|
||||
- :enum_query_double (Float): Query parameter enum test (double)
|
||||
|
||||
## Returns
|
||||
|
||||
{:ok, %{}} on success
|
||||
{:error, info} on failure
|
||||
"""
|
||||
@spec test_enum_parameters(Tesla.Env.client, keyword()) :: {:ok, nil} | {:error, Tesla.Env.t}
|
||||
def test_enum_parameters(connection, opts \\ []) do
|
||||
optional_params = %{
|
||||
:"enum_form_string_array" => :form,
|
||||
:"enum_form_string" => :form,
|
||||
:"enum_header_string_array" => :headers,
|
||||
:"enum_header_string" => :headers,
|
||||
:"enum_query_string_array" => :query,
|
||||
:"enum_query_string" => :query,
|
||||
:"enum_query_integer" => :query,
|
||||
:"enum_query_double" => :form
|
||||
}
|
||||
%{}
|
||||
|> method(:get)
|
||||
|> url("/fake")
|
||||
|> add_optional_params(optional_params, opts)
|
||||
|> Enum.into([])
|
||||
|> (&Connection.request(connection, &1)).()
|
||||
|> decode(false)
|
||||
end
|
||||
|
||||
@doc """
|
||||
test json serialization of form data
|
||||
|
||||
|
||||
Test serialization of outer string types
|
||||
## Parameters
|
||||
|
||||
- connection (SwaggerPetstore.Connection): Connection to server
|
||||
- param (String): field1
|
||||
- param2 (String): field2
|
||||
- opts (KeywordList): [optional] Optional parameters
|
||||
|
||||
## Returns
|
||||
|
||||
{:ok, %{}} on success
|
||||
{:error, info} on failure
|
||||
"""
|
||||
def fake_outer_string_serialize(body) do
|
||||
method = [method: :post]
|
||||
url = [url: "/fake/outer/string"]
|
||||
query_params = []
|
||||
header_params = []
|
||||
body_params = [body: body]
|
||||
form_params = []
|
||||
params = query_params ++ header_params ++ body_params ++ form_params
|
||||
opts = []
|
||||
options = method ++ url ++ params ++ opts
|
||||
|
||||
request(options)
|
||||
end
|
||||
|
||||
@doc """
|
||||
To test \"client\" model
|
||||
|
||||
To test \"client\" model
|
||||
"""
|
||||
def test_client_model(body) do
|
||||
method = [method: :patch]
|
||||
url = [url: "/fake"]
|
||||
query_params = []
|
||||
header_params = []
|
||||
body_params = [body: body]
|
||||
form_params = []
|
||||
params = query_params ++ header_params ++ body_params ++ form_params
|
||||
opts = []
|
||||
options = method ++ url ++ params ++ opts
|
||||
|
||||
request(options)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
|
||||
|
||||
Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
|
||||
"""
|
||||
def test_endpoint_parameters(number, double, pattern_without_delimiter, byte, integer, int32, int64, float, string, binary, date, date_time, password, callback) do
|
||||
method = [method: :post]
|
||||
url = [url: "/fake"]
|
||||
query_params = []
|
||||
header_params = []
|
||||
body_params = []
|
||||
form_params = [body: Enum.map_join([{:"integer", integer}, {:"int32", int32}, {:"int64", int64}, {:"number", number}, {:"float", float}, {:"double", double}, {:"string", string}, {:"pattern_without_delimiter", pattern_without_delimiter}, {:"byte", byte}, {:"binary", binary}, {:"date", date}, {:"dateTime", date_time}, {:"password", password}, {:"callback", callback}], "&", &("#{elem(&1, 0)}=#{elem(&1, 1)}"))]
|
||||
params = query_params ++ header_params ++ body_params ++ form_params
|
||||
opts = []
|
||||
options = method ++ url ++ params ++ opts
|
||||
|
||||
request(options)
|
||||
end
|
||||
|
||||
@doc """
|
||||
To test enum parameters
|
||||
|
||||
To test enum parameters
|
||||
"""
|
||||
def test_enum_parameters(enum_form_string_array, enum_form_string, enum_header_string_array, enum_header_string, enum_query_string_array, enum_query_string, enum_query_integer, enum_query_double) do
|
||||
method = [method: :get]
|
||||
url = [url: "/fake"]
|
||||
query_params = [query: [{:"enum_query_string_array", enum_query_string_array}, {:"enum_query_string", enum_query_string}, {:"enum_query_integer", enum_query_integer}]]
|
||||
header_params = [header: [{:"enum_header_string_array", enum_header_string_array}, {:"enum_header_string", enum_header_string}]]
|
||||
body_params = []
|
||||
form_params = [body: Enum.map_join([{:"enum_form_string_array", enum_form_string_array}, {:"enum_form_string", enum_form_string}, {:"enum_query_double", enum_query_double}], "&", &("#{elem(&1, 0)}=#{elem(&1, 1)}"))]
|
||||
params = query_params ++ header_params ++ body_params ++ form_params
|
||||
opts = []
|
||||
options = method ++ url ++ params ++ opts
|
||||
|
||||
request(options)
|
||||
@spec test_json_form_data(Tesla.Env.client, String.t, String.t, keyword()) :: {:ok, nil} | {:error, Tesla.Env.t}
|
||||
def test_json_form_data(connection, param, param2, _opts \\ []) do
|
||||
%{}
|
||||
|> method(:get)
|
||||
|> url("/fake/jsonFormData")
|
||||
|> add_param(:form, :"param", param)
|
||||
|> add_param(:form, :"param2", param2)
|
||||
|> Enum.into([])
|
||||
|> (&Connection.request(connection, &1)).()
|
||||
|> decode(false)
|
||||
end
|
||||
|
||||
@doc """
|
||||
|
@ -1,24 +1,38 @@
|
||||
defmodule SwaggerPetstore.Api.Fake_classname_tags123 do
|
||||
# NOTE: This class is auto generated by the swagger code generator program.
|
||||
# https://github.com/swagger-api/swagger-codegen.git
|
||||
# Do not edit the class manually.
|
||||
|
||||
defmodule SwaggerPetstore.Api.FakeClassnameTags123 do
|
||||
@moduledoc """
|
||||
Documentation for SwaggerPetstore.Api.Fake_classname_tags123.
|
||||
API calls for all endpoints tagged `FakeClassnameTags123`.
|
||||
"""
|
||||
|
||||
use Tesla
|
||||
alias SwaggerPetstore.Connection
|
||||
import SwaggerPetstore.RequestBuilder
|
||||
|
||||
plug Tesla.Middleware.BaseUrl, "http://petstore.swagger.io/v2"
|
||||
plug Tesla.Middleware.JSON
|
||||
|
||||
def test_classname(body) do
|
||||
method = [method: :patch]
|
||||
url = [url: "/fake_classname_test"]
|
||||
query_params = []
|
||||
header_params = []
|
||||
body_params = [body: body]
|
||||
form_params = []
|
||||
params = query_params ++ header_params ++ body_params ++ form_params
|
||||
opts = []
|
||||
options = method ++ url ++ params ++ opts
|
||||
@doc """
|
||||
To test class name in snake case
|
||||
|
||||
request(options)
|
||||
## Parameters
|
||||
|
||||
- connection (SwaggerPetstore.Connection): Connection to server
|
||||
- body (Client): client model
|
||||
- opts (KeywordList): [optional] Optional parameters
|
||||
|
||||
## Returns
|
||||
|
||||
{:ok, %SwaggerPetstore.Model.Client{}} on success
|
||||
{:error, info} on failure
|
||||
"""
|
||||
@spec test_classname(Tesla.Env.client, SwaggerPetstore.Model.Client.t, keyword()) :: {:ok, SwaggerPetstore.Model.Client.t} | {:error, Tesla.Env.t}
|
||||
def test_classname(connection, body, _opts \\ []) do
|
||||
%{}
|
||||
|> method(:patch)
|
||||
|> url("/fake_classname_test")
|
||||
|> add_param(:body, :"body", body)
|
||||
|> Enum.into([])
|
||||
|> (&Connection.request(connection, &1)).()
|
||||
|> decode(%SwaggerPetstore.Model.Client{})
|
||||
end
|
||||
end
|
||||
|
@ -1,152 +1,236 @@
|
||||
# NOTE: This class is auto generated by the swagger code generator program.
|
||||
# https://github.com/swagger-api/swagger-codegen.git
|
||||
# Do not edit the class manually.
|
||||
|
||||
defmodule SwaggerPetstore.Api.Pet do
|
||||
@moduledoc """
|
||||
Documentation for SwaggerPetstore.Api.Pet.
|
||||
API calls for all endpoints tagged `Pet`.
|
||||
"""
|
||||
|
||||
use Tesla
|
||||
alias SwaggerPetstore.Connection
|
||||
import SwaggerPetstore.RequestBuilder
|
||||
|
||||
plug Tesla.Middleware.BaseUrl, "http://petstore.swagger.io:80/v2"
|
||||
plug Tesla.Middleware.JSON
|
||||
|
||||
@doc """
|
||||
Add a new pet to the store
|
||||
"""
|
||||
def add_pet(body) do
|
||||
method = [method: :post]
|
||||
url = [url: "/pet"]
|
||||
query_params = []
|
||||
header_params = []
|
||||
body_params = [body: body]
|
||||
form_params = []
|
||||
params = query_params ++ header_params ++ body_params ++ form_params
|
||||
opts = []
|
||||
options = method ++ url ++ params ++ opts
|
||||
|
||||
|
||||
request(options)
|
||||
## Parameters
|
||||
|
||||
- connection (SwaggerPetstore.Connection): Connection to server
|
||||
- body (Pet): Pet object that needs to be added to the store
|
||||
- opts (KeywordList): [optional] Optional parameters
|
||||
|
||||
## Returns
|
||||
|
||||
{:ok, %{}} on success
|
||||
{:error, info} on failure
|
||||
"""
|
||||
@spec add_pet(Tesla.Env.client, SwaggerPetstore.Model.Pet.t, keyword()) :: {:ok, nil} | {:error, Tesla.Env.t}
|
||||
def add_pet(connection, body, _opts \\ []) do
|
||||
%{}
|
||||
|> method(:post)
|
||||
|> url("/pet")
|
||||
|> add_param(:body, :"body", body)
|
||||
|> Enum.into([])
|
||||
|> (&Connection.request(connection, &1)).()
|
||||
|> decode(false)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Deletes a pet
|
||||
"""
|
||||
def delete_pet(pet_id, api_key) do
|
||||
method = [method: :delete]
|
||||
url = [url: "/pet/#{pet_id}"]
|
||||
query_params = []
|
||||
header_params = [header: [{:"api_key", api_key}]]
|
||||
body_params = []
|
||||
form_params = []
|
||||
params = query_params ++ header_params ++ body_params ++ form_params
|
||||
opts = []
|
||||
options = method ++ url ++ params ++ opts
|
||||
|
||||
|
||||
request(options)
|
||||
## Parameters
|
||||
|
||||
- connection (SwaggerPetstore.Connection): Connection to server
|
||||
- pet_id (Integer): Pet id to delete
|
||||
- opts (KeywordList): [optional] Optional parameters
|
||||
- :api_key (String):
|
||||
|
||||
## Returns
|
||||
|
||||
{:ok, %{}} on success
|
||||
{:error, info} on failure
|
||||
"""
|
||||
@spec delete_pet(Tesla.Env.client, Integer.t, keyword()) :: {:ok, nil} | {:error, Tesla.Env.t}
|
||||
def delete_pet(connection, pet_id, opts \\ []) do
|
||||
optional_params = %{
|
||||
:"api_key" => :headers
|
||||
}
|
||||
%{}
|
||||
|> method(:delete)
|
||||
|> url("/pet/#{pet_id}")
|
||||
|> add_optional_params(optional_params, opts)
|
||||
|> Enum.into([])
|
||||
|> (&Connection.request(connection, &1)).()
|
||||
|> decode(false)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Finds Pets by status
|
||||
|
||||
Multiple status values can be provided with comma separated strings
|
||||
"""
|
||||
def find_pets_by_status(status) do
|
||||
method = [method: :get]
|
||||
url = [url: "/pet/findByStatus"]
|
||||
query_params = [query: [{:"status", status}]]
|
||||
header_params = []
|
||||
body_params = []
|
||||
form_params = []
|
||||
params = query_params ++ header_params ++ body_params ++ form_params
|
||||
opts = []
|
||||
options = method ++ url ++ params ++ opts
|
||||
|
||||
request(options)
|
||||
## Parameters
|
||||
|
||||
- connection (SwaggerPetstore.Connection): Connection to server
|
||||
- status (List[String]): Status values that need to be considered for filter
|
||||
- opts (KeywordList): [optional] Optional parameters
|
||||
|
||||
## Returns
|
||||
|
||||
{:ok, [%Pet{}, ...]} on success
|
||||
{:error, info} on failure
|
||||
"""
|
||||
@spec find_pets_by_status(Tesla.Env.client, list(String.t), keyword()) :: {:ok, list(SwaggerPetstore.Model.Pet.t)} | {:error, Tesla.Env.t}
|
||||
def find_pets_by_status(connection, status, _opts \\ []) do
|
||||
%{}
|
||||
|> method(:get)
|
||||
|> url("/pet/findByStatus")
|
||||
|> add_param(:query, :"status", status)
|
||||
|> Enum.into([])
|
||||
|> (&Connection.request(connection, &1)).()
|
||||
|> decode([%SwaggerPetstore.Model.Pet{}])
|
||||
end
|
||||
|
||||
@doc """
|
||||
Finds Pets by tags
|
||||
|
||||
Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
||||
"""
|
||||
def find_pets_by_tags(tags) do
|
||||
method = [method: :get]
|
||||
url = [url: "/pet/findByTags"]
|
||||
query_params = [query: [{:"tags", tags}]]
|
||||
header_params = []
|
||||
body_params = []
|
||||
form_params = []
|
||||
params = query_params ++ header_params ++ body_params ++ form_params
|
||||
opts = []
|
||||
options = method ++ url ++ params ++ opts
|
||||
|
||||
request(options)
|
||||
## Parameters
|
||||
|
||||
- connection (SwaggerPetstore.Connection): Connection to server
|
||||
- tags (List[String]): Tags to filter by
|
||||
- opts (KeywordList): [optional] Optional parameters
|
||||
|
||||
## Returns
|
||||
|
||||
{:ok, [%Pet{}, ...]} on success
|
||||
{:error, info} on failure
|
||||
"""
|
||||
@spec find_pets_by_tags(Tesla.Env.client, list(String.t), keyword()) :: {:ok, list(SwaggerPetstore.Model.Pet.t)} | {:error, Tesla.Env.t}
|
||||
def find_pets_by_tags(connection, tags, _opts \\ []) do
|
||||
%{}
|
||||
|> method(:get)
|
||||
|> url("/pet/findByTags")
|
||||
|> add_param(:query, :"tags", tags)
|
||||
|> Enum.into([])
|
||||
|> (&Connection.request(connection, &1)).()
|
||||
|> decode([%SwaggerPetstore.Model.Pet{}])
|
||||
end
|
||||
|
||||
@doc """
|
||||
Find pet by ID
|
||||
|
||||
Returns a single pet
|
||||
"""
|
||||
def get_pet_by_id(pet_id) do
|
||||
method = [method: :get]
|
||||
url = [url: "/pet/#{pet_id}"]
|
||||
query_params = []
|
||||
header_params = []
|
||||
body_params = []
|
||||
form_params = []
|
||||
params = query_params ++ header_params ++ body_params ++ form_params
|
||||
opts = []
|
||||
options = method ++ url ++ params ++ opts
|
||||
|
||||
request(options)
|
||||
## Parameters
|
||||
|
||||
- connection (SwaggerPetstore.Connection): Connection to server
|
||||
- pet_id (Integer): ID of pet to return
|
||||
- opts (KeywordList): [optional] Optional parameters
|
||||
|
||||
## Returns
|
||||
|
||||
{:ok, %SwaggerPetstore.Model.Pet{}} on success
|
||||
{:error, info} on failure
|
||||
"""
|
||||
@spec get_pet_by_id(Tesla.Env.client, Integer.t, keyword()) :: {:ok, SwaggerPetstore.Model.Pet.t} | {:error, Tesla.Env.t}
|
||||
def get_pet_by_id(connection, pet_id, _opts \\ []) do
|
||||
%{}
|
||||
|> method(:get)
|
||||
|> url("/pet/#{pet_id}")
|
||||
|> Enum.into([])
|
||||
|> (&Connection.request(connection, &1)).()
|
||||
|> decode(%SwaggerPetstore.Model.Pet{})
|
||||
end
|
||||
|
||||
@doc """
|
||||
Update an existing pet
|
||||
"""
|
||||
def update_pet(body) do
|
||||
method = [method: :put]
|
||||
url = [url: "/pet"]
|
||||
query_params = []
|
||||
header_params = []
|
||||
body_params = [body: body]
|
||||
form_params = []
|
||||
params = query_params ++ header_params ++ body_params ++ form_params
|
||||
opts = []
|
||||
options = method ++ url ++ params ++ opts
|
||||
|
||||
|
||||
request(options)
|
||||
## Parameters
|
||||
|
||||
- connection (SwaggerPetstore.Connection): Connection to server
|
||||
- body (Pet): Pet object that needs to be added to the store
|
||||
- opts (KeywordList): [optional] Optional parameters
|
||||
|
||||
## Returns
|
||||
|
||||
{:ok, %{}} on success
|
||||
{:error, info} on failure
|
||||
"""
|
||||
@spec update_pet(Tesla.Env.client, SwaggerPetstore.Model.Pet.t, keyword()) :: {:ok, nil} | {:error, Tesla.Env.t}
|
||||
def update_pet(connection, body, _opts \\ []) do
|
||||
%{}
|
||||
|> method(:put)
|
||||
|> url("/pet")
|
||||
|> add_param(:body, :"body", body)
|
||||
|> Enum.into([])
|
||||
|> (&Connection.request(connection, &1)).()
|
||||
|> decode(false)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Updates a pet in the store with form data
|
||||
"""
|
||||
def update_pet_with_form(pet_id, name, status) do
|
||||
method = [method: :post]
|
||||
url = [url: "/pet/#{pet_id}"]
|
||||
query_params = []
|
||||
header_params = []
|
||||
body_params = []
|
||||
form_params = [body: Enum.map_join([{:"name", name}, {:"status", status}], "&", &("#{elem(&1, 0)}=#{elem(&1, 1)}"))]
|
||||
params = query_params ++ header_params ++ body_params ++ form_params
|
||||
opts = []
|
||||
options = method ++ url ++ params ++ opts
|
||||
|
||||
|
||||
request(options)
|
||||
## Parameters
|
||||
|
||||
- connection (SwaggerPetstore.Connection): Connection to server
|
||||
- pet_id (Integer): ID of pet that needs to be updated
|
||||
- opts (KeywordList): [optional] Optional parameters
|
||||
- :name (String): Updated name of the pet
|
||||
- :status (String): Updated status of the pet
|
||||
|
||||
## Returns
|
||||
|
||||
{:ok, %{}} on success
|
||||
{:error, info} on failure
|
||||
"""
|
||||
@spec update_pet_with_form(Tesla.Env.client, Integer.t, keyword()) :: {:ok, nil} | {:error, Tesla.Env.t}
|
||||
def update_pet_with_form(connection, pet_id, opts \\ []) do
|
||||
optional_params = %{
|
||||
:"name" => :form,
|
||||
:"status" => :form
|
||||
}
|
||||
%{}
|
||||
|> method(:post)
|
||||
|> url("/pet/#{pet_id}")
|
||||
|> add_optional_params(optional_params, opts)
|
||||
|> Enum.into([])
|
||||
|> (&Connection.request(connection, &1)).()
|
||||
|> decode(false)
|
||||
end
|
||||
|
||||
@doc """
|
||||
uploads an image
|
||||
"""
|
||||
def upload_file(pet_id, additional_metadata, file) do
|
||||
method = [method: :post]
|
||||
url = [url: "/pet/#{pet_id}/uploadImage"]
|
||||
query_params = []
|
||||
header_params = []
|
||||
body_params = []
|
||||
form_params = [body: Enum.map_join([{:"additionalMetadata", additional_metadata}, {:"file", file}], "&", &("#{elem(&1, 0)}=#{elem(&1, 1)}"))]
|
||||
params = query_params ++ header_params ++ body_params ++ form_params
|
||||
opts = []
|
||||
options = method ++ url ++ params ++ opts
|
||||
|
||||
|
||||
request(options)
|
||||
## Parameters
|
||||
|
||||
- connection (SwaggerPetstore.Connection): Connection to server
|
||||
- pet_id (Integer): ID of pet to update
|
||||
- opts (KeywordList): [optional] Optional parameters
|
||||
- :additional_metadata (String): Additional data to pass to server
|
||||
- :file (String): file to upload
|
||||
|
||||
## Returns
|
||||
|
||||
{:ok, %SwaggerPetstore.Model.ApiResponse{}} on success
|
||||
{:error, info} on failure
|
||||
"""
|
||||
@spec upload_file(Tesla.Env.client, Integer.t, keyword()) :: {:ok, SwaggerPetstore.Model.ApiResponse.t} | {:error, Tesla.Env.t}
|
||||
def upload_file(connection, pet_id, opts \\ []) do
|
||||
optional_params = %{
|
||||
:"additionalMetadata" => :form,
|
||||
:"file" => :form
|
||||
}
|
||||
%{}
|
||||
|> method(:post)
|
||||
|> url("/pet/#{pet_id}/uploadImage")
|
||||
|> add_optional_params(optional_params, opts)
|
||||
|> Enum.into([])
|
||||
|> (&Connection.request(connection, &1)).()
|
||||
|> decode(%SwaggerPetstore.Model.ApiResponse{})
|
||||
end
|
||||
end
|
||||
|
@ -1,84 +1,113 @@
|
||||
# NOTE: This class is auto generated by the swagger code generator program.
|
||||
# https://github.com/swagger-api/swagger-codegen.git
|
||||
# Do not edit the class manually.
|
||||
|
||||
defmodule SwaggerPetstore.Api.Store do
|
||||
@moduledoc """
|
||||
Documentation for SwaggerPetstore.Api.Store.
|
||||
API calls for all endpoints tagged `Store`.
|
||||
"""
|
||||
|
||||
use Tesla
|
||||
alias SwaggerPetstore.Connection
|
||||
import SwaggerPetstore.RequestBuilder
|
||||
|
||||
plug Tesla.Middleware.BaseUrl, "http://petstore.swagger.io:80/v2"
|
||||
plug Tesla.Middleware.JSON
|
||||
|
||||
@doc """
|
||||
Delete purchase order by ID
|
||||
|
||||
For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
|
||||
"""
|
||||
def delete_order(order_id) do
|
||||
method = [method: :delete]
|
||||
url = [url: "/store/order/#{order_id}"]
|
||||
query_params = []
|
||||
header_params = []
|
||||
body_params = []
|
||||
form_params = []
|
||||
params = query_params ++ header_params ++ body_params ++ form_params
|
||||
opts = []
|
||||
options = method ++ url ++ params ++ opts
|
||||
|
||||
request(options)
|
||||
## Parameters
|
||||
|
||||
- connection (SwaggerPetstore.Connection): Connection to server
|
||||
- order_id (String): ID of the order that needs to be deleted
|
||||
- opts (KeywordList): [optional] Optional parameters
|
||||
|
||||
## Returns
|
||||
|
||||
{:ok, %{}} on success
|
||||
{:error, info} on failure
|
||||
"""
|
||||
@spec delete_order(Tesla.Env.client, String.t, keyword()) :: {:ok, nil} | {:error, Tesla.Env.t}
|
||||
def delete_order(connection, order_id, _opts \\ []) do
|
||||
%{}
|
||||
|> method(:delete)
|
||||
|> url("/store/order/#{order_id}")
|
||||
|> Enum.into([])
|
||||
|> (&Connection.request(connection, &1)).()
|
||||
|> decode(false)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns pet inventories by status
|
||||
|
||||
Returns a map of status codes to quantities
|
||||
"""
|
||||
def get_inventory() do
|
||||
method = [method: :get]
|
||||
url = [url: "/store/inventory"]
|
||||
query_params = []
|
||||
header_params = []
|
||||
body_params = []
|
||||
form_params = []
|
||||
params = query_params ++ header_params ++ body_params ++ form_params
|
||||
opts = []
|
||||
options = method ++ url ++ params ++ opts
|
||||
|
||||
request(options)
|
||||
## Parameters
|
||||
|
||||
- connection (SwaggerPetstore.Connection): Connection to server
|
||||
- opts (KeywordList): [optional] Optional parameters
|
||||
|
||||
## Returns
|
||||
|
||||
{:ok, %{}} on success
|
||||
{:error, info} on failure
|
||||
"""
|
||||
@spec get_inventory(Tesla.Env.client, keyword()) :: {:ok, map()} | {:error, Tesla.Env.t}
|
||||
def get_inventory(connection, _opts \\ []) do
|
||||
%{}
|
||||
|> method(:get)
|
||||
|> url("/store/inventory")
|
||||
|> Enum.into([])
|
||||
|> (&Connection.request(connection, &1)).()
|
||||
|> decode()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Find purchase order by ID
|
||||
|
||||
For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
|
||||
"""
|
||||
def get_order_by_id(order_id) do
|
||||
method = [method: :get]
|
||||
url = [url: "/store/order/#{order_id}"]
|
||||
query_params = []
|
||||
header_params = []
|
||||
body_params = []
|
||||
form_params = []
|
||||
params = query_params ++ header_params ++ body_params ++ form_params
|
||||
opts = []
|
||||
options = method ++ url ++ params ++ opts
|
||||
|
||||
request(options)
|
||||
## Parameters
|
||||
|
||||
- connection (SwaggerPetstore.Connection): Connection to server
|
||||
- order_id (Integer): ID of pet that needs to be fetched
|
||||
- opts (KeywordList): [optional] Optional parameters
|
||||
|
||||
## Returns
|
||||
|
||||
{:ok, %SwaggerPetstore.Model.Order{}} on success
|
||||
{:error, info} on failure
|
||||
"""
|
||||
@spec get_order_by_id(Tesla.Env.client, Integer.t, keyword()) :: {:ok, SwaggerPetstore.Model.Order.t} | {:error, Tesla.Env.t}
|
||||
def get_order_by_id(connection, order_id, _opts \\ []) do
|
||||
%{}
|
||||
|> method(:get)
|
||||
|> url("/store/order/#{order_id}")
|
||||
|> Enum.into([])
|
||||
|> (&Connection.request(connection, &1)).()
|
||||
|> decode(%SwaggerPetstore.Model.Order{})
|
||||
end
|
||||
|
||||
@doc """
|
||||
Place an order for a pet
|
||||
"""
|
||||
def place_order(body) do
|
||||
method = [method: :post]
|
||||
url = [url: "/store/order"]
|
||||
query_params = []
|
||||
header_params = []
|
||||
body_params = [body: body]
|
||||
form_params = []
|
||||
params = query_params ++ header_params ++ body_params ++ form_params
|
||||
opts = []
|
||||
options = method ++ url ++ params ++ opts
|
||||
|
||||
|
||||
request(options)
|
||||
## Parameters
|
||||
|
||||
- connection (SwaggerPetstore.Connection): Connection to server
|
||||
- body (Order): order placed for purchasing the pet
|
||||
- opts (KeywordList): [optional] Optional parameters
|
||||
|
||||
## Returns
|
||||
|
||||
{:ok, %SwaggerPetstore.Model.Order{}} on success
|
||||
{:error, info} on failure
|
||||
"""
|
||||
@spec place_order(Tesla.Env.client, SwaggerPetstore.Model.Order.t, keyword()) :: {:ok, SwaggerPetstore.Model.Order.t} | {:error, Tesla.Env.t}
|
||||
def place_order(connection, body, _opts \\ []) do
|
||||
%{}
|
||||
|> method(:post)
|
||||
|> url("/store/order")
|
||||
|> add_param(:body, :"body", body)
|
||||
|> Enum.into([])
|
||||
|> (&Connection.request(connection, &1)).()
|
||||
|> decode(%SwaggerPetstore.Model.Order{})
|
||||
end
|
||||
end
|
||||
|
@ -1,152 +1,220 @@
|
||||
# NOTE: This class is auto generated by the swagger code generator program.
|
||||
# https://github.com/swagger-api/swagger-codegen.git
|
||||
# Do not edit the class manually.
|
||||
|
||||
defmodule SwaggerPetstore.Api.User do
|
||||
@moduledoc """
|
||||
Documentation for SwaggerPetstore.Api.User.
|
||||
API calls for all endpoints tagged `User`.
|
||||
"""
|
||||
|
||||
use Tesla
|
||||
alias SwaggerPetstore.Connection
|
||||
import SwaggerPetstore.RequestBuilder
|
||||
|
||||
plug Tesla.Middleware.BaseUrl, "http://petstore.swagger.io:80/v2"
|
||||
plug Tesla.Middleware.JSON
|
||||
|
||||
@doc """
|
||||
Create user
|
||||
|
||||
This can only be done by the logged in user.
|
||||
"""
|
||||
def create_user(body) do
|
||||
method = [method: :post]
|
||||
url = [url: "/user"]
|
||||
query_params = []
|
||||
header_params = []
|
||||
body_params = [body: body]
|
||||
form_params = []
|
||||
params = query_params ++ header_params ++ body_params ++ form_params
|
||||
opts = []
|
||||
options = method ++ url ++ params ++ opts
|
||||
|
||||
request(options)
|
||||
## Parameters
|
||||
|
||||
- connection (SwaggerPetstore.Connection): Connection to server
|
||||
- body (User): Created user object
|
||||
- opts (KeywordList): [optional] Optional parameters
|
||||
|
||||
## Returns
|
||||
|
||||
{:ok, %{}} on success
|
||||
{:error, info} on failure
|
||||
"""
|
||||
@spec create_user(Tesla.Env.client, SwaggerPetstore.Model.User.t, keyword()) :: {:ok, nil} | {:error, Tesla.Env.t}
|
||||
def create_user(connection, body, _opts \\ []) do
|
||||
%{}
|
||||
|> method(:post)
|
||||
|> url("/user")
|
||||
|> add_param(:body, :"body", body)
|
||||
|> Enum.into([])
|
||||
|> (&Connection.request(connection, &1)).()
|
||||
|> decode(false)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Creates list of users with given input array
|
||||
"""
|
||||
def create_users_with_array_input(body) do
|
||||
method = [method: :post]
|
||||
url = [url: "/user/createWithArray"]
|
||||
query_params = []
|
||||
header_params = []
|
||||
body_params = [body: body]
|
||||
form_params = []
|
||||
params = query_params ++ header_params ++ body_params ++ form_params
|
||||
opts = []
|
||||
options = method ++ url ++ params ++ opts
|
||||
|
||||
|
||||
request(options)
|
||||
## Parameters
|
||||
|
||||
- connection (SwaggerPetstore.Connection): Connection to server
|
||||
- body (List[User]): List of user object
|
||||
- opts (KeywordList): [optional] Optional parameters
|
||||
|
||||
## Returns
|
||||
|
||||
{:ok, %{}} on success
|
||||
{:error, info} on failure
|
||||
"""
|
||||
@spec create_users_with_array_input(Tesla.Env.client, list(SwaggerPetstore.Model.User.t), keyword()) :: {:ok, nil} | {:error, Tesla.Env.t}
|
||||
def create_users_with_array_input(connection, body, _opts \\ []) do
|
||||
%{}
|
||||
|> method(:post)
|
||||
|> url("/user/createWithArray")
|
||||
|> add_param(:body, :"body", body)
|
||||
|> Enum.into([])
|
||||
|> (&Connection.request(connection, &1)).()
|
||||
|> decode(false)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Creates list of users with given input array
|
||||
"""
|
||||
def create_users_with_list_input(body) do
|
||||
method = [method: :post]
|
||||
url = [url: "/user/createWithList"]
|
||||
query_params = []
|
||||
header_params = []
|
||||
body_params = [body: body]
|
||||
form_params = []
|
||||
params = query_params ++ header_params ++ body_params ++ form_params
|
||||
opts = []
|
||||
options = method ++ url ++ params ++ opts
|
||||
|
||||
|
||||
request(options)
|
||||
## Parameters
|
||||
|
||||
- connection (SwaggerPetstore.Connection): Connection to server
|
||||
- body (List[User]): List of user object
|
||||
- opts (KeywordList): [optional] Optional parameters
|
||||
|
||||
## Returns
|
||||
|
||||
{:ok, %{}} on success
|
||||
{:error, info} on failure
|
||||
"""
|
||||
@spec create_users_with_list_input(Tesla.Env.client, list(SwaggerPetstore.Model.User.t), keyword()) :: {:ok, nil} | {:error, Tesla.Env.t}
|
||||
def create_users_with_list_input(connection, body, _opts \\ []) do
|
||||
%{}
|
||||
|> method(:post)
|
||||
|> url("/user/createWithList")
|
||||
|> add_param(:body, :"body", body)
|
||||
|> Enum.into([])
|
||||
|> (&Connection.request(connection, &1)).()
|
||||
|> decode(false)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Delete user
|
||||
|
||||
This can only be done by the logged in user.
|
||||
"""
|
||||
def delete_user(username) do
|
||||
method = [method: :delete]
|
||||
url = [url: "/user/#{username}"]
|
||||
query_params = []
|
||||
header_params = []
|
||||
body_params = []
|
||||
form_params = []
|
||||
params = query_params ++ header_params ++ body_params ++ form_params
|
||||
opts = []
|
||||
options = method ++ url ++ params ++ opts
|
||||
|
||||
request(options)
|
||||
## Parameters
|
||||
|
||||
- connection (SwaggerPetstore.Connection): Connection to server
|
||||
- username (String): The name that needs to be deleted
|
||||
- opts (KeywordList): [optional] Optional parameters
|
||||
|
||||
## Returns
|
||||
|
||||
{:ok, %{}} on success
|
||||
{:error, info} on failure
|
||||
"""
|
||||
@spec delete_user(Tesla.Env.client, String.t, keyword()) :: {:ok, nil} | {:error, Tesla.Env.t}
|
||||
def delete_user(connection, username, _opts \\ []) do
|
||||
%{}
|
||||
|> method(:delete)
|
||||
|> url("/user/#{username}")
|
||||
|> Enum.into([])
|
||||
|> (&Connection.request(connection, &1)).()
|
||||
|> decode(false)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Get user by user name
|
||||
"""
|
||||
def get_user_by_name(username) do
|
||||
method = [method: :get]
|
||||
url = [url: "/user/#{username}"]
|
||||
query_params = []
|
||||
header_params = []
|
||||
body_params = []
|
||||
form_params = []
|
||||
params = query_params ++ header_params ++ body_params ++ form_params
|
||||
opts = []
|
||||
options = method ++ url ++ params ++ opts
|
||||
|
||||
|
||||
request(options)
|
||||
## Parameters
|
||||
|
||||
- connection (SwaggerPetstore.Connection): Connection to server
|
||||
- username (String): The name that needs to be fetched. Use user1 for testing.
|
||||
- opts (KeywordList): [optional] Optional parameters
|
||||
|
||||
## Returns
|
||||
|
||||
{:ok, %SwaggerPetstore.Model.User{}} on success
|
||||
{:error, info} on failure
|
||||
"""
|
||||
@spec get_user_by_name(Tesla.Env.client, String.t, keyword()) :: {:ok, SwaggerPetstore.Model.User.t} | {:error, Tesla.Env.t}
|
||||
def get_user_by_name(connection, username, _opts \\ []) do
|
||||
%{}
|
||||
|> method(:get)
|
||||
|> url("/user/#{username}")
|
||||
|> Enum.into([])
|
||||
|> (&Connection.request(connection, &1)).()
|
||||
|> decode(%SwaggerPetstore.Model.User{})
|
||||
end
|
||||
|
||||
@doc """
|
||||
Logs user into the system
|
||||
"""
|
||||
def login_user(username, password) do
|
||||
method = [method: :get]
|
||||
url = [url: "/user/login"]
|
||||
query_params = [query: [{:"username", username}, {:"password", password}]]
|
||||
header_params = []
|
||||
body_params = []
|
||||
form_params = []
|
||||
params = query_params ++ header_params ++ body_params ++ form_params
|
||||
opts = []
|
||||
options = method ++ url ++ params ++ opts
|
||||
|
||||
|
||||
request(options)
|
||||
## Parameters
|
||||
|
||||
- connection (SwaggerPetstore.Connection): Connection to server
|
||||
- username (String): The user name for login
|
||||
- password (String): The password for login in clear text
|
||||
- opts (KeywordList): [optional] Optional parameters
|
||||
|
||||
## Returns
|
||||
|
||||
{:ok, %SwaggerPetstore.Model.String{}} on success
|
||||
{:error, info} on failure
|
||||
"""
|
||||
@spec login_user(Tesla.Env.client, String.t, String.t, keyword()) :: {:ok, String.t} | {:error, Tesla.Env.t}
|
||||
def login_user(connection, username, password, _opts \\ []) do
|
||||
%{}
|
||||
|> method(:get)
|
||||
|> url("/user/login")
|
||||
|> add_param(:query, :"username", username)
|
||||
|> add_param(:query, :"password", password)
|
||||
|> Enum.into([])
|
||||
|> (&Connection.request(connection, &1)).()
|
||||
|> decode(false)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Logs out current logged in user session
|
||||
"""
|
||||
def logout_user() do
|
||||
method = [method: :get]
|
||||
url = [url: "/user/logout"]
|
||||
query_params = []
|
||||
header_params = []
|
||||
body_params = []
|
||||
form_params = []
|
||||
params = query_params ++ header_params ++ body_params ++ form_params
|
||||
opts = []
|
||||
options = method ++ url ++ params ++ opts
|
||||
|
||||
|
||||
request(options)
|
||||
## Parameters
|
||||
|
||||
- connection (SwaggerPetstore.Connection): Connection to server
|
||||
- opts (KeywordList): [optional] Optional parameters
|
||||
|
||||
## Returns
|
||||
|
||||
{:ok, %{}} on success
|
||||
{:error, info} on failure
|
||||
"""
|
||||
@spec logout_user(Tesla.Env.client, keyword()) :: {:ok, nil} | {:error, Tesla.Env.t}
|
||||
def logout_user(connection, _opts \\ []) do
|
||||
%{}
|
||||
|> method(:get)
|
||||
|> url("/user/logout")
|
||||
|> Enum.into([])
|
||||
|> (&Connection.request(connection, &1)).()
|
||||
|> decode(false)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Updated user
|
||||
|
||||
This can only be done by the logged in user.
|
||||
"""
|
||||
def update_user(username, body) do
|
||||
method = [method: :put]
|
||||
url = [url: "/user/#{username}"]
|
||||
query_params = []
|
||||
header_params = []
|
||||
body_params = [body: body]
|
||||
form_params = []
|
||||
params = query_params ++ header_params ++ body_params ++ form_params
|
||||
opts = []
|
||||
options = method ++ url ++ params ++ opts
|
||||
|
||||
request(options)
|
||||
## Parameters
|
||||
|
||||
- connection (SwaggerPetstore.Connection): Connection to server
|
||||
- username (String): name that need to be deleted
|
||||
- body (User): Updated user object
|
||||
- opts (KeywordList): [optional] Optional parameters
|
||||
|
||||
## Returns
|
||||
|
||||
{:ok, %{}} on success
|
||||
{:error, info} on failure
|
||||
"""
|
||||
@spec update_user(Tesla.Env.client, String.t, SwaggerPetstore.Model.User.t, keyword()) :: {:ok, nil} | {:error, Tesla.Env.t}
|
||||
def update_user(connection, username, body, _opts \\ []) do
|
||||
%{}
|
||||
|> method(:put)
|
||||
|> url("/user/#{username}")
|
||||
|> add_param(:body, :"body", body)
|
||||
|> Enum.into([])
|
||||
|> (&Connection.request(connection, &1)).()
|
||||
|> decode(false)
|
||||
end
|
||||
end
|
||||
|
@ -0,0 +1,86 @@
|
||||
# NOTE: This class is auto generated by the swagger code generator program.
|
||||
# https://github.com/swagger-api/swagger-codegen.git
|
||||
# Do not edit the class manually.
|
||||
|
||||
defmodule SwaggerPetstore.Connection do
|
||||
@moduledoc """
|
||||
Handle Tesla connections for SwaggerPetstore.
|
||||
"""
|
||||
|
||||
use Tesla
|
||||
|
||||
# Add any middleware here (authentication)
|
||||
plug Tesla.Middleware.BaseUrl, "http://petstore.swagger.io:80/v2"
|
||||
plug Tesla.Middleware.Headers, %{"User-Agent" => "Elixir"}
|
||||
plug Tesla.Middleware.EncodeJson
|
||||
|
||||
@doc """
|
||||
Configure an client connection using Basic authentication.
|
||||
|
||||
## Parameters
|
||||
|
||||
- username (String): Username used for authentication
|
||||
- password (String): Password used for authentication
|
||||
|
||||
# Returns
|
||||
|
||||
Tesla.Env.client
|
||||
"""
|
||||
@spec new(String.t, String.t) :: Tesla.Env.client
|
||||
def new(username, password) do
|
||||
Tesla.build_client([
|
||||
{Tesla.Middleware.BasicAuth, %{username: username, password: password}}
|
||||
])
|
||||
end
|
||||
@scopes [
|
||||
"write:pets", # modify pets in your account
|
||||
"read:pets" # read your pets
|
||||
]
|
||||
|
||||
@doc """
|
||||
Configure a client connection using a provided OAuth2 token as a Bearer token
|
||||
|
||||
## Parameters
|
||||
|
||||
- token (String): Bearer token
|
||||
|
||||
## Returns
|
||||
|
||||
Tesla.Env.client
|
||||
"""
|
||||
@spec new(String.t) :: Tesla.Env.client
|
||||
def new(token) when is_binary(token) do
|
||||
Tesla.build_client([
|
||||
{Tesla.Middleware.Headers, %{"Authorization" => "Bearer #{token}"}}
|
||||
])
|
||||
end
|
||||
|
||||
@doc """
|
||||
Configure a client connection using a function which yields a Bearer token.
|
||||
|
||||
## Parameters
|
||||
|
||||
- token_fetcher (function arity of 1): Callback which provides an OAuth2 token
|
||||
given a list of scopes
|
||||
|
||||
## Returns
|
||||
|
||||
Tesla.Env.client
|
||||
"""
|
||||
@spec new(((list(String.t)) -> String.t)) :: Tesla.Env.client
|
||||
def new(token_fetcher) when is_function(token_fetcher) do
|
||||
token_fetcher.(@scopes)
|
||||
|> new
|
||||
end
|
||||
@doc """
|
||||
Configure an authless client connection
|
||||
|
||||
# Returns
|
||||
|
||||
Tesla.Env.client
|
||||
"""
|
||||
@spec new() :: Tesla.Env.client
|
||||
def new do
|
||||
Tesla.build_client([])
|
||||
end
|
||||
end
|
@ -0,0 +1,34 @@
|
||||
# NOTE: This class is auto generated by the swagger code generator program.
|
||||
# https://github.com/swagger-api/swagger-codegen.git
|
||||
# Do not edit the class manually.
|
||||
|
||||
defmodule SwaggerPetstore.Deserializer do
|
||||
@moduledoc """
|
||||
Helper functions for deserializing responses into models
|
||||
"""
|
||||
|
||||
@doc """
|
||||
Update the provided model with a deserialization of a nested value
|
||||
"""
|
||||
@spec deserialize(struct(), :atom, :atom, struct(), keyword()) :: struct()
|
||||
def deserialize(model, field, :list, mod, options) do
|
||||
model
|
||||
|> Map.update!(field, &(Poison.Decode.decode(&1, Keyword.merge(options, [as: [struct(mod)]]))))
|
||||
end
|
||||
def deserialize(model, field, :struct, mod, options) do
|
||||
model
|
||||
|> Map.update!(field, &(Poison.Decode.decode(&1, Keyword.merge(options, [as: struct(mod)]))))
|
||||
end
|
||||
def deserialize(model, field, :map, mod, options) do
|
||||
model
|
||||
|> Map.update!(field, &(Map.new(&1, fn {key, val} -> {key, Poison.Decode.decode(val, Keyword.merge(options, [as: struct(mod)]))} end)))
|
||||
end
|
||||
def deserialize(model, field, :date, _, _options) do
|
||||
case DateTime.from_iso8601(Map.get(model, field)) do
|
||||
{:ok, datetime} ->
|
||||
Map.put(model, field, datetime)
|
||||
_ ->
|
||||
model
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,22 @@
|
||||
# NOTE: This class is auto generated by the swagger code generator program.
|
||||
# https://github.com/swagger-api/swagger-codegen.git
|
||||
# Do not edit the class manually.
|
||||
|
||||
defmodule SwaggerPetstore.Model.200_response do
|
||||
@moduledoc """
|
||||
Model for testing model name starting with number
|
||||
"""
|
||||
|
||||
@derive [Poison.Encoder]
|
||||
defstruct [
|
||||
:"name",
|
||||
:"class"
|
||||
]
|
||||
end
|
||||
|
||||
defimpl Poison.Decoder, for: SwaggerPetstore.Model.200_response do
|
||||
def decode(value, _options) do
|
||||
value
|
||||
end
|
||||
end
|
||||
|
@ -0,0 +1,21 @@
|
||||
# NOTE: This class is auto generated by the swagger code generator program.
|
||||
# https://github.com/swagger-api/swagger-codegen.git
|
||||
# Do not edit the class manually.
|
||||
|
||||
defmodule SwaggerPetstore.Model.$special[model.name] do
|
||||
@moduledoc """
|
||||
|
||||
"""
|
||||
|
||||
@derive [Poison.Encoder]
|
||||
defstruct [
|
||||
:"$special[property.name]"
|
||||
]
|
||||
end
|
||||
|
||||
defimpl Poison.Decoder, for: SwaggerPetstore.Model.$special[model.name] do
|
||||
def decode(value, _options) do
|
||||
value
|
||||
end
|
||||
end
|
||||
|
@ -0,0 +1,22 @@
|
||||
# NOTE: This class is auto generated by the swagger code generator program.
|
||||
# https://github.com/swagger-api/swagger-codegen.git
|
||||
# Do not edit the class manually.
|
||||
|
||||
defmodule SwaggerPetstore.Model.AdditionalPropertiesClass do
|
||||
@moduledoc """
|
||||
|
||||
"""
|
||||
|
||||
@derive [Poison.Encoder]
|
||||
defstruct [
|
||||
:"map_property",
|
||||
:"map_of_map_property"
|
||||
]
|
||||
end
|
||||
|
||||
defimpl Poison.Decoder, for: SwaggerPetstore.Model.AdditionalPropertiesClass do
|
||||
def decode(value, _options) do
|
||||
value
|
||||
end
|
||||
end
|
||||
|
@ -0,0 +1,22 @@
|
||||
# NOTE: This class is auto generated by the swagger code generator program.
|
||||
# https://github.com/swagger-api/swagger-codegen.git
|
||||
# Do not edit the class manually.
|
||||
|
||||
defmodule SwaggerPetstore.Model.Animal do
|
||||
@moduledoc """
|
||||
|
||||
"""
|
||||
|
||||
@derive [Poison.Encoder]
|
||||
defstruct [
|
||||
:"className",
|
||||
:"color"
|
||||
]
|
||||
end
|
||||
|
||||
defimpl Poison.Decoder, for: SwaggerPetstore.Model.Animal do
|
||||
def decode(value, _options) do
|
||||
value
|
||||
end
|
||||
end
|
||||
|
@ -0,0 +1,21 @@
|
||||
# NOTE: This class is auto generated by the swagger code generator program.
|
||||
# https://github.com/swagger-api/swagger-codegen.git
|
||||
# Do not edit the class manually.
|
||||
|
||||
defmodule SwaggerPetstore.Model.AnimalFarm do
|
||||
@moduledoc """
|
||||
|
||||
"""
|
||||
|
||||
@derive [Poison.Encoder]
|
||||
defstruct [
|
||||
|
||||
]
|
||||
end
|
||||
|
||||
defimpl Poison.Decoder, for: SwaggerPetstore.Model.AnimalFarm do
|
||||
def decode(value, _options) do
|
||||
value
|
||||
end
|
||||
end
|
||||
|
@ -0,0 +1,23 @@
|
||||
# NOTE: This class is auto generated by the swagger code generator program.
|
||||
# https://github.com/swagger-api/swagger-codegen.git
|
||||
# Do not edit the class manually.
|
||||
|
||||
defmodule SwaggerPetstore.Model.ApiResponse do
|
||||
@moduledoc """
|
||||
|
||||
"""
|
||||
|
||||
@derive [Poison.Encoder]
|
||||
defstruct [
|
||||
:"code",
|
||||
:"type",
|
||||
:"message"
|
||||
]
|
||||
end
|
||||
|
||||
defimpl Poison.Decoder, for: SwaggerPetstore.Model.ApiResponse do
|
||||
def decode(value, _options) do
|
||||
value
|
||||
end
|
||||
end
|
||||
|
@ -0,0 +1,21 @@
|
||||
# NOTE: This class is auto generated by the swagger code generator program.
|
||||
# https://github.com/swagger-api/swagger-codegen.git
|
||||
# Do not edit the class manually.
|
||||
|
||||
defmodule SwaggerPetstore.Model.ArrayOfArrayOfNumberOnly do
|
||||
@moduledoc """
|
||||
|
||||
"""
|
||||
|
||||
@derive [Poison.Encoder]
|
||||
defstruct [
|
||||
:"ArrayArrayNumber"
|
||||
]
|
||||
end
|
||||
|
||||
defimpl Poison.Decoder, for: SwaggerPetstore.Model.ArrayOfArrayOfNumberOnly do
|
||||
def decode(value, _options) do
|
||||
value
|
||||
end
|
||||
end
|
||||
|
@ -0,0 +1,21 @@
|
||||
# NOTE: This class is auto generated by the swagger code generator program.
|
||||
# https://github.com/swagger-api/swagger-codegen.git
|
||||
# Do not edit the class manually.
|
||||
|
||||
defmodule SwaggerPetstore.Model.ArrayOfNumberOnly do
|
||||
@moduledoc """
|
||||
|
||||
"""
|
||||
|
||||
@derive [Poison.Encoder]
|
||||
defstruct [
|
||||
:"ArrayNumber"
|
||||
]
|
||||
end
|
||||
|
||||
defimpl Poison.Decoder, for: SwaggerPetstore.Model.ArrayOfNumberOnly do
|
||||
def decode(value, _options) do
|
||||
value
|
||||
end
|
||||
end
|
||||
|
@ -0,0 +1,23 @@
|
||||
# NOTE: This class is auto generated by the swagger code generator program.
|
||||
# https://github.com/swagger-api/swagger-codegen.git
|
||||
# Do not edit the class manually.
|
||||
|
||||
defmodule SwaggerPetstore.Model.ArrayTest do
|
||||
@moduledoc """
|
||||
|
||||
"""
|
||||
|
||||
@derive [Poison.Encoder]
|
||||
defstruct [
|
||||
:"array_of_string",
|
||||
:"array_array_of_integer",
|
||||
:"array_array_of_model"
|
||||
]
|
||||
end
|
||||
|
||||
defimpl Poison.Decoder, for: SwaggerPetstore.Model.ArrayTest do
|
||||
def decode(value, _options) do
|
||||
value
|
||||
end
|
||||
end
|
||||
|
@ -0,0 +1,26 @@
|
||||
# NOTE: This class is auto generated by the swagger code generator program.
|
||||
# https://github.com/swagger-api/swagger-codegen.git
|
||||
# Do not edit the class manually.
|
||||
|
||||
defmodule SwaggerPetstore.Model.Capitalization do
|
||||
@moduledoc """
|
||||
|
||||
"""
|
||||
|
||||
@derive [Poison.Encoder]
|
||||
defstruct [
|
||||
:"smallCamel",
|
||||
:"CapitalCamel",
|
||||
:"small_Snake",
|
||||
:"Capital_Snake",
|
||||
:"SCA_ETH_Flow_Points",
|
||||
:"ATT_NAME"
|
||||
]
|
||||
end
|
||||
|
||||
defimpl Poison.Decoder, for: SwaggerPetstore.Model.Capitalization do
|
||||
def decode(value, _options) do
|
||||
value
|
||||
end
|
||||
end
|
||||
|
@ -0,0 +1,23 @@
|
||||
# NOTE: This class is auto generated by the swagger code generator program.
|
||||
# https://github.com/swagger-api/swagger-codegen.git
|
||||
# Do not edit the class manually.
|
||||
|
||||
defmodule SwaggerPetstore.Model.Cat do
|
||||
@moduledoc """
|
||||
|
||||
"""
|
||||
|
||||
@derive [Poison.Encoder]
|
||||
defstruct [
|
||||
:"className",
|
||||
:"color",
|
||||
:"declawed"
|
||||
]
|
||||
end
|
||||
|
||||
defimpl Poison.Decoder, for: SwaggerPetstore.Model.Cat do
|
||||
def decode(value, _options) do
|
||||
value
|
||||
end
|
||||
end
|
||||
|
@ -0,0 +1,22 @@
|
||||
# NOTE: This class is auto generated by the swagger code generator program.
|
||||
# https://github.com/swagger-api/swagger-codegen.git
|
||||
# Do not edit the class manually.
|
||||
|
||||
defmodule SwaggerPetstore.Model.Category do
|
||||
@moduledoc """
|
||||
|
||||
"""
|
||||
|
||||
@derive [Poison.Encoder]
|
||||
defstruct [
|
||||
:"id",
|
||||
:"name"
|
||||
]
|
||||
end
|
||||
|
||||
defimpl Poison.Decoder, for: SwaggerPetstore.Model.Category do
|
||||
def decode(value, _options) do
|
||||
value
|
||||
end
|
||||
end
|
||||
|
@ -0,0 +1,21 @@
|
||||
# NOTE: This class is auto generated by the swagger code generator program.
|
||||
# https://github.com/swagger-api/swagger-codegen.git
|
||||
# Do not edit the class manually.
|
||||
|
||||
defmodule SwaggerPetstore.Model.ClassModel do
|
||||
@moduledoc """
|
||||
Model for testing model with \"_class\" property
|
||||
"""
|
||||
|
||||
@derive [Poison.Encoder]
|
||||
defstruct [
|
||||
:"_class"
|
||||
]
|
||||
end
|
||||
|
||||
defimpl Poison.Decoder, for: SwaggerPetstore.Model.ClassModel do
|
||||
def decode(value, _options) do
|
||||
value
|
||||
end
|
||||
end
|
||||
|
@ -0,0 +1,21 @@
|
||||
# NOTE: This class is auto generated by the swagger code generator program.
|
||||
# https://github.com/swagger-api/swagger-codegen.git
|
||||
# Do not edit the class manually.
|
||||
|
||||
defmodule SwaggerPetstore.Model.Client do
|
||||
@moduledoc """
|
||||
|
||||
"""
|
||||
|
||||
@derive [Poison.Encoder]
|
||||
defstruct [
|
||||
:"client"
|
||||
]
|
||||
end
|
||||
|
||||
defimpl Poison.Decoder, for: SwaggerPetstore.Model.Client do
|
||||
def decode(value, _options) do
|
||||
value
|
||||
end
|
||||
end
|
||||
|
@ -0,0 +1,23 @@
|
||||
# NOTE: This class is auto generated by the swagger code generator program.
|
||||
# https://github.com/swagger-api/swagger-codegen.git
|
||||
# Do not edit the class manually.
|
||||
|
||||
defmodule SwaggerPetstore.Model.Dog do
|
||||
@moduledoc """
|
||||
|
||||
"""
|
||||
|
||||
@derive [Poison.Encoder]
|
||||
defstruct [
|
||||
:"className",
|
||||
:"color",
|
||||
:"breed"
|
||||
]
|
||||
end
|
||||
|
||||
defimpl Poison.Decoder, for: SwaggerPetstore.Model.Dog do
|
||||
def decode(value, _options) do
|
||||
value
|
||||
end
|
||||
end
|
||||
|
@ -0,0 +1,22 @@
|
||||
# NOTE: This class is auto generated by the swagger code generator program.
|
||||
# https://github.com/swagger-api/swagger-codegen.git
|
||||
# Do not edit the class manually.
|
||||
|
||||
defmodule SwaggerPetstore.Model.EnumArrays do
|
||||
@moduledoc """
|
||||
|
||||
"""
|
||||
|
||||
@derive [Poison.Encoder]
|
||||
defstruct [
|
||||
:"just_symbol",
|
||||
:"array_enum"
|
||||
]
|
||||
end
|
||||
|
||||
defimpl Poison.Decoder, for: SwaggerPetstore.Model.EnumArrays do
|
||||
def decode(value, _options) do
|
||||
value
|
||||
end
|
||||
end
|
||||
|
@ -0,0 +1,21 @@
|
||||
# NOTE: This class is auto generated by the swagger code generator program.
|
||||
# https://github.com/swagger-api/swagger-codegen.git
|
||||
# Do not edit the class manually.
|
||||
|
||||
defmodule SwaggerPetstore.Model.EnumClass do
|
||||
@moduledoc """
|
||||
|
||||
"""
|
||||
|
||||
@derive [Poison.Encoder]
|
||||
defstruct [
|
||||
|
||||
]
|
||||
end
|
||||
|
||||
defimpl Poison.Decoder, for: SwaggerPetstore.Model.EnumClass do
|
||||
def decode(value, _options) do
|
||||
value
|
||||
end
|
||||
end
|
||||
|
@ -0,0 +1,26 @@
|
||||
# NOTE: This class is auto generated by the swagger code generator program.
|
||||
# https://github.com/swagger-api/swagger-codegen.git
|
||||
# Do not edit the class manually.
|
||||
|
||||
defmodule SwaggerPetstore.Model.Enum_Test do
|
||||
@moduledoc """
|
||||
|
||||
"""
|
||||
|
||||
@derive [Poison.Encoder]
|
||||
defstruct [
|
||||
:"enum_string",
|
||||
:"enum_integer",
|
||||
:"enum_number",
|
||||
:"outerEnum"
|
||||
]
|
||||
end
|
||||
|
||||
defimpl Poison.Decoder, for: SwaggerPetstore.Model.Enum_Test do
|
||||
import SwaggerPetstore.Deserializer
|
||||
def decode(value, options) do
|
||||
value
|
||||
|> deserialize(:"outerEnum", :struct, SwaggerPetstore.Model.OuterEnum, options)
|
||||
end
|
||||
end
|
||||
|
@ -0,0 +1,35 @@
|
||||
# NOTE: This class is auto generated by the swagger code generator program.
|
||||
# https://github.com/swagger-api/swagger-codegen.git
|
||||
# Do not edit the class manually.
|
||||
|
||||
defmodule SwaggerPetstore.Model.Format_test do
|
||||
@moduledoc """
|
||||
|
||||
"""
|
||||
|
||||
@derive [Poison.Encoder]
|
||||
defstruct [
|
||||
:"integer",
|
||||
:"int32",
|
||||
:"int64",
|
||||
:"number",
|
||||
:"float",
|
||||
:"double",
|
||||
:"string",
|
||||
:"byte",
|
||||
:"binary",
|
||||
:"date",
|
||||
:"dateTime",
|
||||
:"uuid",
|
||||
:"password"
|
||||
]
|
||||
end
|
||||
|
||||
defimpl Poison.Decoder, for: SwaggerPetstore.Model.Format_test do
|
||||
import SwaggerPetstore.Deserializer
|
||||
def decode(value, options) do
|
||||
value
|
||||
|> deserialize(:"date", :date, nil, options)
|
||||
end
|
||||
end
|
||||
|
@ -0,0 +1,22 @@
|
||||
# NOTE: This class is auto generated by the swagger code generator program.
|
||||
# https://github.com/swagger-api/swagger-codegen.git
|
||||
# Do not edit the class manually.
|
||||
|
||||
defmodule SwaggerPetstore.Model.HasOnlyReadOnly do
|
||||
@moduledoc """
|
||||
|
||||
"""
|
||||
|
||||
@derive [Poison.Encoder]
|
||||
defstruct [
|
||||
:"bar",
|
||||
:"foo"
|
||||
]
|
||||
end
|
||||
|
||||
defimpl Poison.Decoder, for: SwaggerPetstore.Model.HasOnlyReadOnly do
|
||||
def decode(value, _options) do
|
||||
value
|
||||
end
|
||||
end
|
||||
|
@ -0,0 +1,22 @@
|
||||
# NOTE: This class is auto generated by the swagger code generator program.
|
||||
# https://github.com/swagger-api/swagger-codegen.git
|
||||
# Do not edit the class manually.
|
||||
|
||||
defmodule SwaggerPetstore.Model.MapTest do
|
||||
@moduledoc """
|
||||
|
||||
"""
|
||||
|
||||
@derive [Poison.Encoder]
|
||||
defstruct [
|
||||
:"map_map_of_string",
|
||||
:"map_of_enum_string"
|
||||
]
|
||||
end
|
||||
|
||||
defimpl Poison.Decoder, for: SwaggerPetstore.Model.MapTest do
|
||||
def decode(value, _options) do
|
||||
value
|
||||
end
|
||||
end
|
||||
|
@ -0,0 +1,25 @@
|
||||
# NOTE: This class is auto generated by the swagger code generator program.
|
||||
# https://github.com/swagger-api/swagger-codegen.git
|
||||
# Do not edit the class manually.
|
||||
|
||||
defmodule SwaggerPetstore.Model.MixedPropertiesAndAdditionalPropertiesClass do
|
||||
@moduledoc """
|
||||
|
||||
"""
|
||||
|
||||
@derive [Poison.Encoder]
|
||||
defstruct [
|
||||
:"uuid",
|
||||
:"dateTime",
|
||||
:"map"
|
||||
]
|
||||
end
|
||||
|
||||
defimpl Poison.Decoder, for: SwaggerPetstore.Model.MixedPropertiesAndAdditionalPropertiesClass do
|
||||
import SwaggerPetstore.Deserializer
|
||||
def decode(value, options) do
|
||||
value
|
||||
|> deserialize(:"map", :map, SwaggerPetstore.Model.Animal, options)
|
||||
end
|
||||
end
|
||||
|
@ -0,0 +1,24 @@
|
||||
# NOTE: This class is auto generated by the swagger code generator program.
|
||||
# https://github.com/swagger-api/swagger-codegen.git
|
||||
# Do not edit the class manually.
|
||||
|
||||
defmodule SwaggerPetstore.Model.Name do
|
||||
@moduledoc """
|
||||
Model for testing model name same as property name
|
||||
"""
|
||||
|
||||
@derive [Poison.Encoder]
|
||||
defstruct [
|
||||
:"name",
|
||||
:"snake_case",
|
||||
:"property",
|
||||
:"123Number"
|
||||
]
|
||||
end
|
||||
|
||||
defimpl Poison.Decoder, for: SwaggerPetstore.Model.Name do
|
||||
def decode(value, _options) do
|
||||
value
|
||||
end
|
||||
end
|
||||
|
@ -0,0 +1,21 @@
|
||||
# NOTE: This class is auto generated by the swagger code generator program.
|
||||
# https://github.com/swagger-api/swagger-codegen.git
|
||||
# Do not edit the class manually.
|
||||
|
||||
defmodule SwaggerPetstore.Model.NumberOnly do
|
||||
@moduledoc """
|
||||
|
||||
"""
|
||||
|
||||
@derive [Poison.Encoder]
|
||||
defstruct [
|
||||
:"JustNumber"
|
||||
]
|
||||
end
|
||||
|
||||
defimpl Poison.Decoder, for: SwaggerPetstore.Model.NumberOnly do
|
||||
def decode(value, _options) do
|
||||
value
|
||||
end
|
||||
end
|
||||
|
@ -0,0 +1,26 @@
|
||||
# NOTE: This class is auto generated by the swagger code generator program.
|
||||
# https://github.com/swagger-api/swagger-codegen.git
|
||||
# Do not edit the class manually.
|
||||
|
||||
defmodule SwaggerPetstore.Model.Order do
|
||||
@moduledoc """
|
||||
|
||||
"""
|
||||
|
||||
@derive [Poison.Encoder]
|
||||
defstruct [
|
||||
:"id",
|
||||
:"petId",
|
||||
:"quantity",
|
||||
:"shipDate",
|
||||
:"status",
|
||||
:"complete"
|
||||
]
|
||||
end
|
||||
|
||||
defimpl Poison.Decoder, for: SwaggerPetstore.Model.Order do
|
||||
def decode(value, _options) do
|
||||
value
|
||||
end
|
||||
end
|
||||
|
@ -0,0 +1,21 @@
|
||||
# NOTE: This class is auto generated by the swagger code generator program.
|
||||
# https://github.com/swagger-api/swagger-codegen.git
|
||||
# Do not edit the class manually.
|
||||
|
||||
defmodule SwaggerPetstore.Model.OuterBoolean do
|
||||
@moduledoc """
|
||||
|
||||
"""
|
||||
|
||||
@derive [Poison.Encoder]
|
||||
defstruct [
|
||||
|
||||
]
|
||||
end
|
||||
|
||||
defimpl Poison.Decoder, for: SwaggerPetstore.Model.OuterBoolean do
|
||||
def decode(value, _options) do
|
||||
value
|
||||
end
|
||||
end
|
||||
|
@ -0,0 +1,27 @@
|
||||
# NOTE: This class is auto generated by the swagger code generator program.
|
||||
# https://github.com/swagger-api/swagger-codegen.git
|
||||
# Do not edit the class manually.
|
||||
|
||||
defmodule SwaggerPetstore.Model.OuterComposite do
|
||||
@moduledoc """
|
||||
|
||||
"""
|
||||
|
||||
@derive [Poison.Encoder]
|
||||
defstruct [
|
||||
:"my_number",
|
||||
:"my_string",
|
||||
:"my_boolean"
|
||||
]
|
||||
end
|
||||
|
||||
defimpl Poison.Decoder, for: SwaggerPetstore.Model.OuterComposite do
|
||||
import SwaggerPetstore.Deserializer
|
||||
def decode(value, options) do
|
||||
value
|
||||
|> deserialize(:"my_number", :struct, SwaggerPetstore.Model.OuterNumber, options)
|
||||
|> deserialize(:"my_string", :struct, SwaggerPetstore.Model.OuterString, options)
|
||||
|> deserialize(:"my_boolean", :struct, SwaggerPetstore.Model.OuterBoolean, options)
|
||||
end
|
||||
end
|
||||
|
@ -0,0 +1,21 @@
|
||||
# NOTE: This class is auto generated by the swagger code generator program.
|
||||
# https://github.com/swagger-api/swagger-codegen.git
|
||||
# Do not edit the class manually.
|
||||
|
||||
defmodule SwaggerPetstore.Model.OuterEnum do
|
||||
@moduledoc """
|
||||
|
||||
"""
|
||||
|
||||
@derive [Poison.Encoder]
|
||||
defstruct [
|
||||
|
||||
]
|
||||
end
|
||||
|
||||
defimpl Poison.Decoder, for: SwaggerPetstore.Model.OuterEnum do
|
||||
def decode(value, _options) do
|
||||
value
|
||||
end
|
||||
end
|
||||
|
@ -0,0 +1,21 @@
|
||||
# NOTE: This class is auto generated by the swagger code generator program.
|
||||
# https://github.com/swagger-api/swagger-codegen.git
|
||||
# Do not edit the class manually.
|
||||
|
||||
defmodule SwaggerPetstore.Model.OuterNumber do
|
||||
@moduledoc """
|
||||
|
||||
"""
|
||||
|
||||
@derive [Poison.Encoder]
|
||||
defstruct [
|
||||
|
||||
]
|
||||
end
|
||||
|
||||
defimpl Poison.Decoder, for: SwaggerPetstore.Model.OuterNumber do
|
||||
def decode(value, _options) do
|
||||
value
|
||||
end
|
||||
end
|
||||
|
@ -0,0 +1,21 @@
|
||||
# NOTE: This class is auto generated by the swagger code generator program.
|
||||
# https://github.com/swagger-api/swagger-codegen.git
|
||||
# Do not edit the class manually.
|
||||
|
||||
defmodule SwaggerPetstore.Model.OuterString do
|
||||
@moduledoc """
|
||||
|
||||
"""
|
||||
|
||||
@derive [Poison.Encoder]
|
||||
defstruct [
|
||||
|
||||
]
|
||||
end
|
||||
|
||||
defimpl Poison.Decoder, for: SwaggerPetstore.Model.OuterString do
|
||||
def decode(value, _options) do
|
||||
value
|
||||
end
|
||||
end
|
||||
|
@ -0,0 +1,29 @@
|
||||
# NOTE: This class is auto generated by the swagger code generator program.
|
||||
# https://github.com/swagger-api/swagger-codegen.git
|
||||
# Do not edit the class manually.
|
||||
|
||||
defmodule SwaggerPetstore.Model.Pet do
|
||||
@moduledoc """
|
||||
|
||||
"""
|
||||
|
||||
@derive [Poison.Encoder]
|
||||
defstruct [
|
||||
:"id",
|
||||
:"category",
|
||||
:"name",
|
||||
:"photoUrls",
|
||||
:"tags",
|
||||
:"status"
|
||||
]
|
||||
end
|
||||
|
||||
defimpl Poison.Decoder, for: SwaggerPetstore.Model.Pet do
|
||||
import SwaggerPetstore.Deserializer
|
||||
def decode(value, options) do
|
||||
value
|
||||
|> deserialize(:"category", :struct, SwaggerPetstore.Model.Category, options)
|
||||
|> deserialize(:"tags", :list, SwaggerPetstore.Model.Tag, options)
|
||||
end
|
||||
end
|
||||
|
@ -0,0 +1,22 @@
|
||||
# NOTE: This class is auto generated by the swagger code generator program.
|
||||
# https://github.com/swagger-api/swagger-codegen.git
|
||||
# Do not edit the class manually.
|
||||
|
||||
defmodule SwaggerPetstore.Model.ReadOnlyFirst do
|
||||
@moduledoc """
|
||||
|
||||
"""
|
||||
|
||||
@derive [Poison.Encoder]
|
||||
defstruct [
|
||||
:"bar",
|
||||
:"baz"
|
||||
]
|
||||
end
|
||||
|
||||
defimpl Poison.Decoder, for: SwaggerPetstore.Model.ReadOnlyFirst do
|
||||
def decode(value, _options) do
|
||||
value
|
||||
end
|
||||
end
|
||||
|
@ -0,0 +1,21 @@
|
||||
# NOTE: This class is auto generated by the swagger code generator program.
|
||||
# https://github.com/swagger-api/swagger-codegen.git
|
||||
# Do not edit the class manually.
|
||||
|
||||
defmodule SwaggerPetstore.Model.Return do
|
||||
@moduledoc """
|
||||
Model for testing reserved words
|
||||
"""
|
||||
|
||||
@derive [Poison.Encoder]
|
||||
defstruct [
|
||||
:"return"
|
||||
]
|
||||
end
|
||||
|
||||
defimpl Poison.Decoder, for: SwaggerPetstore.Model.Return do
|
||||
def decode(value, _options) do
|
||||
value
|
||||
end
|
||||
end
|
||||
|
@ -0,0 +1,22 @@
|
||||
# NOTE: This class is auto generated by the swagger code generator program.
|
||||
# https://github.com/swagger-api/swagger-codegen.git
|
||||
# Do not edit the class manually.
|
||||
|
||||
defmodule SwaggerPetstore.Model.Tag do
|
||||
@moduledoc """
|
||||
|
||||
"""
|
||||
|
||||
@derive [Poison.Encoder]
|
||||
defstruct [
|
||||
:"id",
|
||||
:"name"
|
||||
]
|
||||
end
|
||||
|
||||
defimpl Poison.Decoder, for: SwaggerPetstore.Model.Tag do
|
||||
def decode(value, _options) do
|
||||
value
|
||||
end
|
||||
end
|
||||
|
@ -0,0 +1,28 @@
|
||||
# NOTE: This class is auto generated by the swagger code generator program.
|
||||
# https://github.com/swagger-api/swagger-codegen.git
|
||||
# Do not edit the class manually.
|
||||
|
||||
defmodule SwaggerPetstore.Model.User do
|
||||
@moduledoc """
|
||||
|
||||
"""
|
||||
|
||||
@derive [Poison.Encoder]
|
||||
defstruct [
|
||||
:"id",
|
||||
:"username",
|
||||
:"firstName",
|
||||
:"lastName",
|
||||
:"email",
|
||||
:"password",
|
||||
:"phone",
|
||||
:"userStatus"
|
||||
]
|
||||
end
|
||||
|
||||
defimpl Poison.Decoder, for: SwaggerPetstore.Model.User do
|
||||
def decode(value, _options) do
|
||||
value
|
||||
end
|
||||
end
|
||||
|
@ -0,0 +1,130 @@
|
||||
# NOTE: This class is auto generated by the swagger code generator program.
|
||||
# https://github.com/swagger-api/swagger-codegen.git
|
||||
# Do not edit the class manually.
|
||||
|
||||
defmodule SwaggerPetstore.RequestBuilder do
|
||||
@moduledoc """
|
||||
Helper functions for building Tesla requests
|
||||
"""
|
||||
|
||||
@doc """
|
||||
Specify the request method when building a request
|
||||
|
||||
## Parameters
|
||||
|
||||
- request (Map) - Collected request options
|
||||
- m (String) - Request method
|
||||
|
||||
## Returns
|
||||
|
||||
Map
|
||||
"""
|
||||
@spec method(map(), String.t) :: map()
|
||||
def method(request, m) do
|
||||
Map.put_new(request, :method, m)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Specify the request method when building a request
|
||||
|
||||
## Parameters
|
||||
|
||||
- request (Map) - Collected request options
|
||||
- u (String) - Request URL
|
||||
|
||||
## Returns
|
||||
|
||||
Map
|
||||
"""
|
||||
@spec url(map(), String.t) :: map()
|
||||
def url(request, u) do
|
||||
Map.put_new(request, :url, u)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Add optional parameters to the request
|
||||
|
||||
## Parameters
|
||||
|
||||
- request (Map) - Collected request options
|
||||
- definitions (Map) - Map of parameter name to parameter location.
|
||||
- options (KeywordList) - The provided optional parameters
|
||||
|
||||
## Returns
|
||||
|
||||
Map
|
||||
"""
|
||||
@spec add_optional_params(map(), %{optional(:atom) => :atom}, keyword()) :: map()
|
||||
def add_optional_params(request, _, []), do: request
|
||||
def add_optional_params(request, definitions, [{key, value} | tail]) do
|
||||
case definitions do
|
||||
%{^key => location} ->
|
||||
request
|
||||
|> add_param(location, key, value)
|
||||
|> add_optional_params(definitions, tail)
|
||||
_ ->
|
||||
add_optional_params(request, definitions, tail)
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
Add optional parameters to the request
|
||||
|
||||
## Parameters
|
||||
|
||||
- request (Map) - Collected request options
|
||||
- location (atom) - Where to put the parameter
|
||||
- key (atom) - The name of the parameter
|
||||
- value (any) - The value of the parameter
|
||||
|
||||
## Returns
|
||||
|
||||
Map
|
||||
"""
|
||||
@spec add_param(map(), :atom, :atom, any()) :: map()
|
||||
def add_param(request, :body, :body, value), do: Map.put(request, :body, value)
|
||||
def add_param(request, :body, key, value) do
|
||||
request
|
||||
|> Map.put_new_lazy(:body, &Tesla.Multipart.new/0)
|
||||
|> Map.update!(:body, &(Tesla.Multipart.add_field(&1, key, Poison.encode!(value), headers: [{:"Content-Type", "application/json"}])))
|
||||
end
|
||||
def add_param(request, :file, name, path) do
|
||||
request
|
||||
|> Map.put_new_lazy(:body, &Tesla.Multipart.new/0)
|
||||
|> Map.update!(:body, &(Tesla.Multipart.add_file(&1, path, name: name)))
|
||||
end
|
||||
def add_param(request, :form, name, value) do
|
||||
request
|
||||
|> Map.update(:body, %{name => value}, &(Map.put(&1, name, value)))
|
||||
end
|
||||
def add_param(request, location, key, value) do
|
||||
Map.update(request, location, [{key, value}], &(&1 ++ [{key, value}]))
|
||||
end
|
||||
|
||||
@doc """
|
||||
Handle the response for a Tesla request
|
||||
|
||||
## Parameters
|
||||
|
||||
- env (Tesla.Env) - The response object
|
||||
- struct - The shape of the struct to deserialize into
|
||||
|
||||
## Returns
|
||||
|
||||
{:ok, struct} on success
|
||||
{:error, info} on failure
|
||||
"""
|
||||
@spec decode(Tesla.Env.t) :: {:ok, struct()} | {:error, Tesla.Env.t}
|
||||
def decode(%Tesla.Env{status: 200, body: body}), do: Poison.decode(body)
|
||||
def decode(response) do
|
||||
{:error, response}
|
||||
end
|
||||
@spec decode(Tesla.Env.t, struct()) :: {:ok, struct()} | {:error, Tesla.Env.t}
|
||||
def decode(%Tesla.Env{status: 200} = env, false), do: {:ok, env}
|
||||
def decode(%Tesla.Env{status: 200, body: body}, struct) do
|
||||
Poison.decode(body, as: struct)
|
||||
end
|
||||
def decode(response, _struct) do
|
||||
{:error, response}
|
||||
end
|
||||
end
|
@ -29,7 +29,7 @@ defmodule SwaggerPetstore.Mixfile do
|
||||
# Type "mix help deps" for more examples and options
|
||||
defp deps do
|
||||
[
|
||||
{:tesla, "~> 0.5.0"},
|
||||
{:tesla, "~> 0.8"},
|
||||
{:poison, ">= 1.0.0"}
|
||||
]
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user