Skip to content

Commit 9221076

Browse files
authored
fix: reformat json to yaml based on workflow.yaml (#1612)
Given the following workflow, `out.openapi.yaml` would end up being JSON when in fact it should be YAML based on the suffix. [GEN-1841: bug: workflow does not respect `yaml` extension](https://linear.app/speakeasy/issue/GEN-1841/bug-workflow-does-not-respect-yaml-extension) ```yaml workflowVersion: 1.0.0 speakeasyVersion: latest sources: petstore-oas: inputs: - location: openapi.json output: .speakeasy/out.openapi.yaml registry: location: registry.speakeasyapi.dev/speakeasy-self/speakeasy-self/petstore-oas targets: petstore: target: typescript source: petstore-oas codeSamples: registry: location: registry.speakeasyapi.dev/speakeasy-self/speakeasy-self/petstore-oas-typescript-code-samples labelOverride: fixedValue: Typescript (SDK) blocking: false ```
1 parent 65cedbe commit 9221076

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

internal/run/source.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -315,14 +315,18 @@ func writeToOutputLocation(ctx context.Context, documentPath string, outputLocat
315315
return err
316316
}
317317

318-
// If we have yaml and need json, convert it
319-
if utils.HasYAMLExt(documentPath) && !utils.HasYAMLExt(outputLocation) {
320-
jsonBytes, err := schemas.Format(ctx, documentPath, false)
318+
// Check if we need to convert between formats based on file extensions
319+
sourceIsYAML := utils.HasYAMLExt(documentPath)
320+
targetIsYAML := utils.HasYAMLExt(outputLocation)
321+
322+
// If formats differ, convert appropriately
323+
if sourceIsYAML != targetIsYAML {
324+
formattedBytes, err := schemas.Format(ctx, documentPath, targetIsYAML)
321325
if err != nil {
322326
return fmt.Errorf("failed to format document: %w", err)
323327
}
324328

325-
return os.WriteFile(outputLocation, jsonBytes, 0o644)
329+
return os.WriteFile(outputLocation, formattedBytes, 0o644)
326330
} else {
327331
// Otherwise, just copy the file over
328332
return utils.CopyFile(documentPath, outputLocation)

0 commit comments

Comments
 (0)