Azure / Azure/azure-functions-openapi-extension
The key in schemas of components MUST match the regular expression
- Dominant language
- C#
- Stars
- 388
- Forks
- 202
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the issue**
Hi all
I have an Azure Function v2 with OpenAPI extension added on it.
I have defined a class to return responses, this class has a property of type T, could be any type, included other classes.
I added the OpenApiResponseWithBody attribute to some functions that returns a collection of objects of distinct types using the same response class object that I mentioned above.
The extension generates the swagger.json file with:
1. A schema with a name that don't match the regular expression definition: **_entityResponse_iReadOnlyCollection`1_**
2. If exists more than one function that return collection of objects, the extension creates only one schema
**To Reproduce**
1. Open VS 2022
2. Create an Azure Function project with Http trigger, OpenAPI and .NET 6.0 LTS
3. Create a `returnClass` with two properties, one of these properties of type ``
4. Create two different classes: **ex:** `classOne` and `classTwo`
5. Create one function and return: **ex:** `returnClass>`
6. Create a second function and return: **ex:** `returnClass>`
7. Build and Run
8. Go to http://localhost:port/api/swagger/ui and download the swagger.json file generated by the extension
9. Go to https://editor.swagger.io/ and import the downloaded file
10. Look for the error
**Expected behavior**
The extension will create the correct schemas and their names. **ex:** `$ref: '#/definitions/returnClass_List_classOne'` and `$ref: '#/definitions/returnClass_List_classTwo'`
And
```
definitions:
classOne:
type: object
properties:
id:
format: uuid
type: string
code:
type: string
name:
type: string
classTwo:
type: object
properties:
id:
format: uuid
type: string
description:
type: string
returnClass_List_classOne:
type: object
properties:
property1:
type: boolean
value:
type: array
items:
$ref: '#/definitions/classOne'
returnClass_List_classTwo:
type: object
properties:
property1:
type: boolean
value:
type: array
items:
$ref: '#/definitions/classTwo'
```
**Screenshots**
**Function One**

**Function Two**

**swager.json** generated - paths: Wrong name

**swager.json** generated - definitions: `ProvinceResponse` schema missing

**Environment (please complete the following information, if applicable):**
- OS: Windows 11, 22H2, Build 22621.2215
- Browser edge 116.0.1938.54 (Official build) (64-bit)
- Version [e.g. 22]
- Microsoft.Azure.Functions.Extensions 1.1.0
- Microsoft.Azure.WebJobs.Extensions.OpenApi 1.5.1
- Microsoft.NET.Sdk.Functions 4.2.0
**Additional context**
Add any other context about the problem here.
Contributor guide
Assessment
This issue has not been assessed yet.