Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Resolve schemas in the response bodies for OpenAPI 3.0 #61

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/OperationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,15 @@ private static void BuildMethodReturnTypeStack(IModelType type, List<Stack<IMode

private void BuildMethodParameters(Method method)
{
if (_operation.RequestBody?.Content != null)
{
foreach (var contentDescription in _operation.RequestBody.Content.Values)
{
// Resolve schema for content.
contentDescription.Schema = _swaggerModeler.Resolver.Unwrap(contentDescription.Schema) ?? contentDescription.Schema;
}
}

foreach (var swaggerParameter in DeduplicateParameters(_operation.Parameters))
{
var actualSwaggerParameter = _swaggerModeler.Unwrap(swaggerParameter);
Expand Down
35 changes: 35 additions & 0 deletions test/Resource/Swagger/swagger-response-body.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
openapi: 3.0.0
servers: []
info:
title: Xml Tests
version: 1.0.0
paths: {}
components:
schemas:
ModelPlain:
description: ModelPlain
type: object
properties:
PropertyPlain:
description: PropertyPlain
type: string
PropertyOverridden:
description: PropertyOverride
type: string
paths:
/patients:
post:
summary: Register new patient
requestBody:
required: true
content:
'application/x-www-form-urlencoded':
schema:
$ref: '#/components/schemas/ModelPlain'
responses:
'200':
description: Results of operation
content:
application/json:
schema:
$ref: "#/components/schemas/ModelPlain"
10 changes: 10 additions & 0 deletions test/SwaggerModelerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -687,5 +687,15 @@ public void TestAdditionalProperties()
// is it marked as an 'additionalProperties' bucket?
Assert.True(dictionaryProperty.SupportsAdditionalProperties);
}

[Fact]
public void TestResponseBody()
{
var input = Path.Combine(CodeBaseDirectory, "Resource", "Swagger", "swagger-response-body.yaml");
var modeler = new SwaggerModeler();
var codeModel = modeler.Build(SwaggerParser.Parse(File.ReadAllText(input)));

Assert.Equal(1, codeModel.Methods.Count());
}
}
}
12 changes: 10 additions & 2 deletions test/autorest.modeler.test.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk" >
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<VersionPrefix>1.0.0</VersionPrefix>
<GenerateFullPaths>true</GenerateFullPaths>
Expand All @@ -9,7 +9,7 @@
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>

<Target Name="Nuke" AfterTargets="clean" >
<Target Name="Nuke" AfterTargets="clean">
<Delete Files="$(BaseOutputPath)**;$(BaseIntermediateOutputPath)razor/**;$(BaseIntermediateOutputPath)Debug/**;$(BaseIntermediateOutputPath)Release/**" />
<RemoveDir Directories="$(BaseOutputPath);$(BaseIntermediateOutputPath)/Debug;$(BaseIntermediateOutputPath)/Release" />
</Target>
Expand All @@ -19,6 +19,14 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>

<ItemGroup>
<None Remove="Resource\Swagger\swagger-response-body.yaml" />
</ItemGroup>

<ItemGroup>
<Content Include="Resource\Swagger\swagger-response-body.yaml" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
Expand Down