[Bug]: invalid openapi output running from github actions on ubuntu-latest
Describe the bug
When running the tsp compiler from github actions it produced an invalid openapi file. When I try to parse that schema in to https://editor.swagger.io/ it gives me compile erros.
I am trying to compare a typespec generated openapi file with my dotnet project's openapi file. Using json2yaml and openapi-diff. When parsing to openapi-diff I get a parse error. Also errors are occuring on the editor.swagger.io.
Then I started comparing the output files from the github actions container (running the action locally with act) and also the output from running it from windows.
Below is from my scenario, but in the reproduction section I show the issue with the different output.
All code is here: https://github.com/royberris/TypeSpec.NET You can see the pipeline failing: https://github.com/royberris/TypeSpec.NET/actions/runs/9169657101/job/25210475358
Reproduction
Workflow:
jobs:
compare-openapi:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '20'
- name: Install TypeSpec CLI
run: npm install -g @typespec/compiler
- name: NPM install
run: |
cd typespec
npm install
- name: Generate TypeSpec OpenAPI spec
run: |
tsp compile typespec/main.tsp
The main.tsp
import "@typespec/http";
import "@typespec/rest";
import "@typespec/openapi3";
import "@typespec/versioning";
using TypeSpec.Http;
using TypeSpec.Versioning;
@service({
title: "Weather API",
})
@route("/api/weather")
@versioned(Versions)
namespace Weather {
enum Versions {
"v1"
}
model WeatherResult {
name: string;
givenDate?: plainDate;
}
@get
@route("/weather")
op getWeather(@query location: string, @query date?: plainDate): {
@statusCode statusCode: 200;
@body result: WeatherResult;
};
}
The config
emit:
- "@typespec/openapi3"
The output running TypeSpec from a windows environment:
openapi: 3.0.0
info:
title: Weather API
version: v1
tags: []
paths:
/api/weather/weather:
get:
operationId: getWeather
parameters:
- name: location
in: query
required: true
schema:
type: string
- name: date
in: query
required: false
schema:
type: string
format: date
responses:
'200':
description: The request has succeeded.
content:
application/json:
schema:
$ref: '#/components/schemas/WeatherResult'
components:
schemas:
Versions:
type: string
enum:
- v1
WeatherResult:
type: object
required:
- name
properties:
name:
type: string
givenDate:
type: string
format: date
Running it from the github actions:
openapi: 3.0.0
info:
title: Weather API
version: v1
tags: []
paths:
/api/weather/weather:
get:
operationId: getWeather
parameters:
- name: location
in: query
required: true
schema:
type: string
- name: date
in: query
required: false
schema:
type: string
format: date
responses:
'200':
description: The request has succeeded.
content:
application/json:
schema:
$ref: '#/components/schemas/WeatherResult'
components:
schemas:
Versions:
type: string
enum:
- v1
WeatherResult:
type: object
required:
- name
properties:
value:
name:
value:
type: string
kind: code
givenDate:
value:
type: string
format: date
kind: code
kind: code
Checklist
- [X] Follow our Code of Conduct
- [X] Check that there isn't already an issue that request the same bug to avoid creating a duplicate.
- [X] Check that this is a concrete bug. For Q&A open a GitHub Discussion.
- [X] The provided reproduction is a minimal reproducible example of the bug.
@royberris the problem here seems to be it is loading the global compiler version you have instead of hte one defined in the typespec folder. I think as a workaround for now you can run tsp compile . from the typespec folder instead of above
@timotheeguerin that does seem to resolve the issue. But still unexpected that it outputs that WeatherResult object with the extra value property and the kind properties. Is this because when it is outside the typespec folder it doesn't know the configuration etc?
That is an issue because it is doing some instance of comparaison but loading a différent version of the class. Will keep it open because there is a few things we can do here.
- Have the openapi emitter create its own emitter framework
- Resolve the compiler to use from the main file