Skip to content

Commit

Permalink
SchemaListDiff by objects instead of text
Browse files Browse the repository at this point in the history
  • Loading branch information
Reuven committed Apr 16, 2024
1 parent 534c199 commit 19f9e82
Show file tree
Hide file tree
Showing 10 changed files with 354 additions and 80 deletions.
18 changes: 9 additions & 9 deletions checker/checks-utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,19 @@ func processModifiedPropertiesDiff(propertyPath string, propertyName string, sch

if schemaDiff.AllOfDiff != nil {
for k, v := range schemaDiff.AllOfDiff.Modified {
processModifiedPropertiesDiff(fmt.Sprintf("%s/allOf[%s]", propertyPath, k), "", v, schemaDiff, processor)
processModifiedPropertiesDiff(fmt.Sprintf("%s/allOf[%s]", propertyPath, k), "", v.Diff, schemaDiff, processor)

Check failure on line 78 in checker/checks-utils.go

View workflow job for this annotation

GitHub Actions / 1.22.2 on ubuntu-latest

fmt.Sprintf format %s has arg k of wrong type int

Check failure on line 78 in checker/checks-utils.go

View workflow job for this annotation

GitHub Actions / 1.22.2 on ubuntu-latest

fmt.Sprintf format %s has arg k of wrong type int

Check failure on line 78 in checker/checks-utils.go

View workflow job for this annotation

GitHub Actions / Analyze (go)

fmt.Sprintf format %s has arg k of wrong type int
}
}

if schemaDiff.AnyOfDiff != nil {
for k, v := range schemaDiff.AnyOfDiff.Modified {
processModifiedPropertiesDiff(fmt.Sprintf("%s/anyOf[%s]", propertyPath, k), "", v, schemaDiff, processor)
processModifiedPropertiesDiff(fmt.Sprintf("%s/anyOf[%s]", propertyPath, k), "", v.Diff, schemaDiff, processor)

Check failure on line 84 in checker/checks-utils.go

View workflow job for this annotation

GitHub Actions / 1.22.2 on ubuntu-latest

fmt.Sprintf format %s has arg k of wrong type int

Check failure on line 84 in checker/checks-utils.go

View workflow job for this annotation

GitHub Actions / 1.22.2 on ubuntu-latest

fmt.Sprintf format %s has arg k of wrong type int

Check failure on line 84 in checker/checks-utils.go

View workflow job for this annotation

GitHub Actions / Analyze (go)

fmt.Sprintf format %s has arg k of wrong type int
}
}

if schemaDiff.OneOfDiff != nil {
for k, v := range schemaDiff.OneOfDiff.Modified {
processModifiedPropertiesDiff(fmt.Sprintf("%s/oneOf[%s]", propertyPath, k), "", v, schemaDiff, processor)
processModifiedPropertiesDiff(fmt.Sprintf("%s/oneOf[%s]", propertyPath, k), "", v.Diff, schemaDiff, processor)

Check failure on line 90 in checker/checks-utils.go

View workflow job for this annotation

GitHub Actions / 1.22.2 on ubuntu-latest

fmt.Sprintf format %s has arg k of wrong type int

Check failure on line 90 in checker/checks-utils.go

View workflow job for this annotation

GitHub Actions / 1.22.2 on ubuntu-latest

fmt.Sprintf format %s has arg k of wrong type int

Check failure on line 90 in checker/checks-utils.go

View workflow job for this annotation

GitHub Actions / Analyze (go)

fmt.Sprintf format %s has arg k of wrong type int
}
}

Expand Down Expand Up @@ -120,19 +120,19 @@ func processAddedPropertiesDiff(propertyPath string, propertyName string, schema

if schemaDiff.AllOfDiff != nil {
for k, v := range schemaDiff.AllOfDiff.Modified {
processAddedPropertiesDiff(fmt.Sprintf("%s/allOf[%s]", propertyPath, k), "", v, schemaDiff, processor)
processAddedPropertiesDiff(fmt.Sprintf("%s/allOf[%s]", propertyPath, k), "", v.Diff, schemaDiff, processor)

Check failure on line 123 in checker/checks-utils.go

View workflow job for this annotation

GitHub Actions / 1.22.2 on ubuntu-latest

fmt.Sprintf format %s has arg k of wrong type int

Check failure on line 123 in checker/checks-utils.go

View workflow job for this annotation

GitHub Actions / 1.22.2 on ubuntu-latest

fmt.Sprintf format %s has arg k of wrong type int

Check failure on line 123 in checker/checks-utils.go

View workflow job for this annotation

GitHub Actions / Analyze (go)

fmt.Sprintf format %s has arg k of wrong type int
}
}

if schemaDiff.AnyOfDiff != nil {
for k, v := range schemaDiff.AnyOfDiff.Modified {
processAddedPropertiesDiff(fmt.Sprintf("%s/anyOf[%s]", propertyPath, k), "", v, schemaDiff, processor)
processAddedPropertiesDiff(fmt.Sprintf("%s/anyOf[%s]", propertyPath, k), "", v.Diff, schemaDiff, processor)

Check failure on line 129 in checker/checks-utils.go

View workflow job for this annotation

GitHub Actions / 1.22.2 on ubuntu-latest

fmt.Sprintf format %s has arg k of wrong type int

Check failure on line 129 in checker/checks-utils.go

View workflow job for this annotation

GitHub Actions / 1.22.2 on ubuntu-latest

fmt.Sprintf format %s has arg k of wrong type int

Check failure on line 129 in checker/checks-utils.go

View workflow job for this annotation

GitHub Actions / Analyze (go)

fmt.Sprintf format %s has arg k of wrong type int
}
}

if schemaDiff.OneOfDiff != nil {
for k, v := range schemaDiff.OneOfDiff.Modified {
processAddedPropertiesDiff(fmt.Sprintf("%s/oneOf[%s]", propertyPath, k), "", v, schemaDiff, processor)
processAddedPropertiesDiff(fmt.Sprintf("%s/oneOf[%s]", propertyPath, k), "", v.Diff, schemaDiff, processor)

Check failure on line 135 in checker/checks-utils.go

View workflow job for this annotation

GitHub Actions / 1.22.2 on ubuntu-latest

fmt.Sprintf format %s has arg k of wrong type int

Check failure on line 135 in checker/checks-utils.go

View workflow job for this annotation

GitHub Actions / 1.22.2 on ubuntu-latest

fmt.Sprintf format %s has arg k of wrong type int

Check failure on line 135 in checker/checks-utils.go

View workflow job for this annotation

GitHub Actions / Analyze (go)

fmt.Sprintf format %s has arg k of wrong type int
}
}

Expand Down Expand Up @@ -169,18 +169,18 @@ func processDeletedPropertiesDiff(propertyPath string, propertyName string, sche

if schemaDiff.AllOfDiff != nil {
for k, v := range schemaDiff.AllOfDiff.Modified {
processDeletedPropertiesDiff(fmt.Sprintf("%s/allOf[%s]", propertyPath, k), "", v, schemaDiff, processor)
processDeletedPropertiesDiff(fmt.Sprintf("%s/allOf[%s]", propertyPath, k), "", v.Diff, schemaDiff, processor)

Check failure on line 172 in checker/checks-utils.go

View workflow job for this annotation

GitHub Actions / 1.22.2 on ubuntu-latest

fmt.Sprintf format %s has arg k of wrong type int

Check failure on line 172 in checker/checks-utils.go

View workflow job for this annotation

GitHub Actions / 1.22.2 on ubuntu-latest

fmt.Sprintf format %s has arg k of wrong type int

Check failure on line 172 in checker/checks-utils.go

View workflow job for this annotation

GitHub Actions / Analyze (go)

fmt.Sprintf format %s has arg k of wrong type int
}
}
if schemaDiff.AnyOfDiff != nil {
for k, v := range schemaDiff.AnyOfDiff.Modified {
processDeletedPropertiesDiff(fmt.Sprintf("%s/anyOf[%s]", propertyPath, k), "", v, schemaDiff, processor)
processDeletedPropertiesDiff(fmt.Sprintf("%s/anyOf[%s]", propertyPath, k), "", v.Diff, schemaDiff, processor)

Check failure on line 177 in checker/checks-utils.go

View workflow job for this annotation

GitHub Actions / 1.22.2 on ubuntu-latest

fmt.Sprintf format %s has arg k of wrong type int

Check failure on line 177 in checker/checks-utils.go

View workflow job for this annotation

GitHub Actions / 1.22.2 on ubuntu-latest

fmt.Sprintf format %s has arg k of wrong type int

Check failure on line 177 in checker/checks-utils.go

View workflow job for this annotation

GitHub Actions / Analyze (go)

fmt.Sprintf format %s has arg k of wrong type int
}
}

if schemaDiff.OneOfDiff != nil {
for k, v := range schemaDiff.OneOfDiff.Modified {
processDeletedPropertiesDiff(fmt.Sprintf("%s/oneOf[%s]", propertyPath, k), "", v, schemaDiff, processor)
processDeletedPropertiesDiff(fmt.Sprintf("%s/oneOf[%s]", propertyPath, k), "", v.Diff, schemaDiff, processor)

Check failure on line 183 in checker/checks-utils.go

View workflow job for this annotation

GitHub Actions / 1.22.2 on ubuntu-latest

fmt.Sprintf format %s has arg k of wrong type int

Check failure on line 183 in checker/checks-utils.go

View workflow job for this annotation

GitHub Actions / 1.22.2 on ubuntu-latest

fmt.Sprintf format %s has arg k of wrong type int

Check failure on line 183 in checker/checks-utils.go

View workflow job for this annotation

GitHub Actions / Analyze (go)

fmt.Sprintf format %s has arg k of wrong type int
}
}

Expand Down
83 changes: 83 additions & 0 deletions data/x-of-titles/response-enum-one-of-inline-2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
openapi: 3.0.1
info:
title: Test API
version: "2.0"
tags:
- name: Tests
description: Test tag.
paths:
/api/v2/changeOfResponseFieldValueTiedToEnumTest:
get:
tags:
- Tests
summary: This is a test
description: Test description.
operationId: getTest
requestBody:
description: Test.
content:
application/json:
schema:
$ref: '#/components/schemas/GroupOfRequestObjects'
required: true
responses:
"200":
description: OK
security:
- DigestAuth: []
components:
schemas:
GroupOfRequestObjects:
type: object
description: Enum values
oneOf:
- $ref: "#/components/schemas/ResponseEnumInline"
- $ref: "#/components/schemas/ResponseEnumInline2"
ResponseEnumInline:
type: object
description: Enum values
properties:
eventTypeName:
description: Incident that triggered this alert.
type: object
oneOf:
- title: Billing Event Types
type: string
enum:
- CREDIT_CARD_ABOUT_TO_EXPIRE
- title: Cps Backup Event Types
type: string
enum:
- CPS_SNAPSHOT_STARTED
- CPS_SNAPSHOT_SUCCESSFUL
- CPS_SNAPSHOT_FAILED
- CPS_SNAPSHOT_FALLBACK_SUCCESSFUL
- CPS_SNAPSHOT_FALLBACK_FAILED
- CPS_RESTORE_SUCCESSFUL
- CPS_NEW_EVENT_1
- CPS_NEW_EVENT_2
- CPS_EXPORT_SUCCESSFUL
- CPS_RESTORE_FAILED
- CPS_EXPORT_FAILED
- CPS_SNAPSHOT_DOWNLOAD_REQUEST_FAILED
- CPS_OPLOG_CAUGHT_UP
- title: New Events
type: string
enum:
- NEW_EVENT_1
- NEW_EVENT_2
ResponseEnumInline2:
type: object
description: Enum values
properties:
eventTypeName2:
description: Incident that triggered this alert.
type: object
oneOf:
- enum:
- CREDIT_CARD_ABOUT_TO_EXPIRE
title: Billing Event Types
type: string
DigestAuth:
type: http
scheme: digest
76 changes: 76 additions & 0 deletions data/x-of-titles/response-enum-one-of-inline.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
openapi: 3.0.1
info:
title: Test API
version: "2.0"
tags:
- name: Tests
description: Test tag.
paths:
/api/v2/changeOfResponseFieldValueTiedToEnumTest:
get:
tags:
- Tests
summary: This is a test
description: Test description.
operationId: getTest
requestBody:
description: Test.
content:
application/json:
schema:
$ref: '#/components/schemas/GroupOfRequestObjects'
required: true
responses:
"200":
description: OK
security:
- DigestAuth: []
components:
schemas:
GroupOfRequestObjects:
type: object
description: Enum values
oneOf:
- $ref: "#/components/schemas/ResponseEnumInline"
- $ref: "#/components/schemas/ResponseEnumInline2"
ResponseEnumInline:
type: object
description: Enum values
properties:
eventTypeName:
description: Incident that triggered this alert.
type: object
oneOf:
- enum:
- CREDIT_CARD_ABOUT_TO_EXPIRE
title: Billing Event Types
type: string
- enum:
- CPS_SNAPSHOT_STARTED
- CPS_SNAPSHOT_SUCCESSFUL
- CPS_SNAPSHOT_FAILED
- CPS_SNAPSHOT_FALLBACK_SUCCESSFUL
- CPS_SNAPSHOT_FALLBACK_FAILED
- CPS_RESTORE_SUCCESSFUL
- CPS_EXPORT_SUCCESSFUL
- CPS_RESTORE_FAILED
- CPS_EXPORT_FAILED
- CPS_SNAPSHOT_DOWNLOAD_REQUEST_FAILED
- CPS_OPLOG_CAUGHT_UP
title: Cps Backup Event Types
type: string
ResponseEnumInline2:
type: object
description: Enum values
properties:
eventTypeName2:
description: Incident that triggered this alert.
type: object
oneOf:
- enum:
- CREDIT_CARD_ABOUT_TO_EXPIRE
title: Billing Event Types
type: string
DigestAuth:
type: http
scheme: digest
22 changes: 22 additions & 0 deletions data/x-of-titles/spec6.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
openapi: 3.0.3
info:
title: Test
version: "0.1"
paths:
'/test':
get:
responses:
'200':
description: Success
content:
'application/json':
schema:
anyOf:
- title: Title 2
type: string
- title: Title 2
type: number
- title: Title 3
type: boolean
- title:
type: string
22 changes: 22 additions & 0 deletions data/x-of-titles/spec7.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
openapi: 3.0.3
info:
title: Test
version: "0.1"
paths:
'/test':
get:
responses:
'200':
description: Success
content:
'application/json':
schema:
anyOf:
- title: Title 2
type: string
- title: Title 2
type: number
- title: Title 3
type: boolean
- title:
type: number
25 changes: 25 additions & 0 deletions data/x-of-titles/spec8.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
openapi: 3.0.3
info:
title: Test
version: "0.1"
paths:
'/test':
get:
responses:
'200':
description: Success
content:
'application/json':
schema:
anyOf:
- title: Title 2
type: string
- title: Title 2
type: number
- title: Title 3
type: boolean
- title:
type: number
- title:
type: string

40 changes: 25 additions & 15 deletions diff/modified_schemas.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,40 @@ import (
"github.com/getkin/kin-openapi/openapi3"
)

// ModifiedSchemas is map of schema names to their respective diffs
type ModifiedSchemas map[string]*SchemaDiff
type ModifiedSchema struct {
Base Schema `json:"base,omitempty" yaml:"base,omitempty"`
Revision Schema `json:"revision,omitempty" yaml:"revision,omitempty"`
Diff *SchemaDiff `json:"diff,omitempty" yaml:"diff,omitempty"`
}

type ModifiedSchemas []*ModifiedSchema

// ModifiedSchemasOld is map of schema names to their respective diffs
type ModifiedSchemasOld map[string]*SchemaDiff

func (modifiedSchemas ModifiedSchemas) addSchemaDiff(config *Config, state *state, schemaName string, schemaRef1, schemaRef2 *openapi3.SchemaRef) error {
func (modifiedSchemas ModifiedSchemas) addSchemaDiff(config *Config, state *state, schemaName string, schemaRef1, schemaRef2 *openapi3.SchemaRef) (ModifiedSchemas, error) {

diff, err := getSchemaDiff(config, state, schemaRef1, schemaRef2)
if err != nil {
return err
return nil, err
}
if !diff.Empty() {
modifiedSchemas[schemaName] = diff
modifiedSchemas = append(modifiedSchemas, &ModifiedSchema{
Base: Schema{
// Index: schemaRef1.Index,
Title: schemaRef1.Value.Title,
},
Revision: Schema{
// Index: schemaRef2.Index,
Title: schemaRef2.Value.Title,
},
Diff: diff,
})
}

return nil
return modifiedSchemas, nil
}

func (modifiedSchemas ModifiedSchemas) combine(other ModifiedSchemas) ModifiedSchemas {
result := ModifiedSchemas{}

for ref, d := range modifiedSchemas {
result[ref] = d
}
for ref, d := range other {
result[ref] = d
}
return result
return append(modifiedSchemas, other...)
}
Loading

0 comments on commit 19f9e82

Please sign in to comment.