Skip to content

Commit

Permalink
Add option slice-elements-byval (#986)
Browse files Browse the repository at this point in the history
When enabled, slices won't be generated as pointer-to-type.
  • Loading branch information
jhendrixMSFT authored Jul 6, 2023
1 parent 4fd65af commit e256b4d
Show file tree
Hide file tree
Showing 6 changed files with 230 additions and 225 deletions.
2 changes: 1 addition & 1 deletion .scripts/regeneration.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ const network = './swagger/specification/network/resource-manager/readme.md';
generateFromReadme("armnetwork", network, 'package-2022-09', 'test/network/armnetwork', '--module=armnetwork --azure-arm=true --remove-unreferenced-types --generate-fakes --inject-spans --azcore-version=1.7.0-beta.2');

const compute = './swagger/specification/compute/resource-manager/readme.md';
generateFromReadme("armcompute", compute, 'package-2021-12-01', 'test/compute/armcompute', '--module=armcompute --azure-arm=true --remove-unreferenced-types --generate-fakes --inject-spans --azcore-version=1.7.0-beta.2');
generateFromReadme("armcompute", compute, 'package-2021-12-01', 'test/compute/armcompute', '--module=armcompute --azure-arm=true --remove-unreferenced-types --generate-fakes --inject-spans --azcore-version=1.7.0-beta.2 --slice-elements-byval');

const synapseArtifacts = './swagger/specification/synapse/data-plane/readme.md';
generateFromReadme("azartifacts", synapseArtifacts, 'package-artifacts-composite-v6', 'test/synapse/azartifacts', '--security=AADToken --security-scopes="https://dev.azuresynapse.net/.default" --module="azartifacts" --openapi-type="data-plane"');
Expand Down
3 changes: 3 additions & 0 deletions packages/autorest.go/autorest-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,7 @@ help-content:
- key: generate-fakes
type: boolean
description: When true, enables generation of fake servers. The default is false.
- key: slice-elements-byval
type: boolean
description: When true, slice elements will not be pointer-to-type. The default is false.
```
2 changes: 2 additions & 0 deletions packages/autorest.go/src/transform/namer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ export async function namer(session: Session<CodeModel>) {
const honorBodyPlacement = await session.getValue('honor-body-placement', false);
const rawJSONAsBytes = await session.getValue('rawjson-as-bytes', false);
model.language.go!.rawJSONAsBytes = rawJSONAsBytes;
const sliceElementsByValue = await session.getValue('slice-elements-byval', false);
model.language.go!.sliceElementsByValue = sliceElementsByValue;

// fix up type names
const structNames = new Set<string>();
Expand Down
2 changes: 1 addition & 1 deletion packages/autorest.go/src/transform/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ function schemaTypeToGoType(codeModel: CodeModel, schema: Schema, type: 'Propert
schema.language.go!.rawJSONAsBytes = rawJSONAsBytes;
return '[]byte';
}
arraySchema.language.go!.elementIsPtr = !isTypePassedByValue(arrayElem);
arraySchema.language.go!.elementIsPtr = !isTypePassedByValue(arrayElem) && !<boolean>codeModel.language.go!.sliceElementsByValue;
// passing nil for array elements in headers, paths, and query params
// isn't very useful as we'd just skip nil entries. so disable it.
if (type !== 'Property' && type !== 'InBody') {
Expand Down
Loading

0 comments on commit e256b4d

Please sign in to comment.