Skip to content
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
91 changes: 91 additions & 0 deletions pkg/changes/__snapshots__/changes_field_deprecated_test.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@

[TestChanges_FieldChanges_FieldDeprecated - 1]
# Test: field_deprecated

## Old Spec:
```yaml
openapi: 3.0.0
info:
title: Test API
version: 1.0.0
paths:
/widgets:
post:
operationId: updateWidget
requestBody:
content:
application/json:
schema:
type: object
properties:
color:
type: string
responses:
'200':
description: Success
content:
application/json:
schema:
type: object
properties:
id:
type: string
nickname:
type: string
label:
type: string
```

## New Spec:
```yaml
openapi: 3.0.0
info:
title: Test API
version: 1.0.0
paths:
/widgets:
post:
operationId: updateWidget
requestBody:
content:
application/json:
schema:
type: object
properties:
color:
type: string
deprecated: true
responses:
'200':
description: Success
content:
application/json:
schema:
type: object
properties:
id:
type: string
nickname:
type: string
deprecated: true
label:
type: string
nullable: true
deprecated: true
```

## Compact Mode:
## Typescript SDK Changes:
* `sdk.updateWidget()`:
* `request.color` **Deprecated**
* `response` **Changed** (Breaking ⚠️)

## Full Mode:
## Typescript SDK Changes:
* `sdk.updateWidget()`:
* `request.color` **Deprecated**
* `response` **Changed** (Breaking ⚠️)
- `label` **Changed** (Breaking ⚠️)
- `nickname` **Deprecated**

---
136 changes: 136 additions & 0 deletions pkg/changes/__snapshots__/changes_server_sent_events_test.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@

[TestChanges_MethodChanges_ServerSentEvents - 1]
# Test: server_sent_events

## Old Spec:
```yaml
openapi: 3.0.0
info:
title: Test API
version: 1.0.0
paths:
/reports:
post:
operationId: generateReport
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/ReportRequest'
responses:
'200':
description: Success
content:
application/json:
schema:
$ref: '#/components/schemas/Report'
text/event-stream:
schema:
$ref: '#/components/schemas/ReportEvent'
components:
schemas:
ReportRequest:
type: object
required: [format]
properties:
format:
type: string
enum: [pdf, csv]
Report:
type: object
properties:
id:
type: string
ReportEvent:
type: object
properties:
data:
type: string
```

## New Spec:
```yaml
openapi: 3.0.0
info:
title: Test API
version: 1.0.0
paths:
/reports:
post:
operationId: generateReport
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/ReportRequest'
responses:
'200':
description: Success
content:
application/json:
schema:
$ref: '#/components/schemas/Report'
text/event-stream:
schema:
$ref: '#/components/schemas/ReportEvent'
/widgets:
post:
operationId: createWidget
responses:
'200':
description: Success
content:
application/json:
schema:
$ref: '#/components/schemas/Report'
text/event-stream:
schema:
$ref: '#/components/schemas/ReportEvent'
/events:
get:
operationId: tailEvents
responses:
'200':
description: Success
content:
text/event-stream:
schema:
$ref: '#/components/schemas/ReportEvent'
components:
schemas:
ReportRequest:
type: object
required: [format]
properties:
format:
type: string
enum: [pdf, csv, html]
Report:
type: object
properties:
id:
type: string
ReportEvent:
type: object
properties:
data:
type: string
```

## Compact Mode:
## Python SDK Changes:
* `sdk.create_widget()`: **Added**
* `sdk.tail_events()`: **Added**
* `sdk.generate_report()`:
* `request.format.enum(html)` **Added**

## Full Mode:
## Python SDK Changes:
* `sdk.create_widget()`: **Added**
* `sdk.tail_events()`: **Added**
* `sdk.generate_report()`:
* `request.format.enum(html)` **Added**

---
6 changes: 6 additions & 0 deletions pkg/changes/changes.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"path/filepath"

generationaccess "github.com/speakeasy-api/generation-context/access"
"github.com/speakeasy-api/openapi-generation/v2/internal/analytics"
"github.com/speakeasy-api/openapi-generation/v2/internal/ast"
"github.com/speakeasy-api/openapi-generation/v2/internal/document"
Expand Down Expand Up @@ -107,6 +108,11 @@ func resolveAST(ctx context.Context, config GenerateOptions) (*ast.AST, *subsyst
if config.Logger == nil {
config.Logger = logging.NewLogger(zapcore.DebugLevel)
}
// The generator skips operations that use feature-gated constructs, such as
// server-sent event responses, when no generation access state is present.
if _, ok := generationaccess.StateFromContext(ctx); !ok {
ctx = generationaccess.WithDirect(ctx)
}
// Check if schema file exists
if _, err := os.Stat(config.SchemaPath); err != nil {
// If file doesn't exist, return nil AST and nil Subsystem
Expand Down
90 changes: 90 additions & 0 deletions pkg/changes/changes_field_deprecated_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package changes

import (
"testing"

"github.com/gkampitakis/go-snaps/snaps"
)

func TestChanges_FieldChanges_FieldDeprecated(t *testing.T) {
Comment thread
mfbx9da4 marked this conversation as resolved.
oldSpec := `openapi: 3.0.0
info:
title: Test API
version: 1.0.0
paths:
/widgets:
post:
operationId: updateWidget
requestBody:
content:
application/json:
schema:
type: object
properties:
color:
type: string
responses:
'200':
description: Success
content:
application/json:
schema:
type: object
properties:
id:
type: string
nickname:
type: string
label:
type: string`

newSpec := `openapi: 3.0.0
info:
title: Test API
version: 1.0.0
paths:
/widgets:
post:
operationId: updateWidget
requestBody:
content:
application/json:
schema:
type: object
properties:
color:
type: string
deprecated: true
responses:
'200':
description: Success
content:
application/json:
schema:
type: object
properties:
id:
type: string
nickname:
type: string
deprecated: true
label:
type: string
nullable: true
deprecated: true`

lang := "typescript"
oldConfig, newConfig := createTestConfigs(t, testSpecPair{
oldSpec: oldSpec,
newSpec: newSpec,
lang: lang,
})

diff, err := Changes(t.Context(), oldConfig, newConfig)
if err != nil {
t.Fatalf("failed to get changes. error: %s", err.Error())
}

snapshot := formatTestSnapshotWithDiff("field_deprecated", oldSpec, newSpec, diff)
snaps.MatchSnapshot(t, snapshot)
}
Loading
Loading