Skip to content

Commit

Permalink
enhace #793: return odata sanitize property name as well in Dataset M…
Browse files Browse the repository at this point in the history
…etadata (#873)
  • Loading branch information
sadiqkhoja authored May 17, 2023
1 parent 43a150b commit 8b7d8d0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
4 changes: 3 additions & 1 deletion docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Here major and breaking changes to the API are listed by version.

**Changed**:
- ETag support has been added for [Download Dataset](#reference/datasets/download-dataset/download-dataset) and [Download Form Attachment](#reference/forms/individual-form/downloading-a-form-attachment).
- [Dataset Metadata endpoint](#reference/datasets/datasets/dataset-metadata) also returns sanitized property names as `odataName` to match the way they will be outputted for OData.

### ODK Central v2023.2

Expand Down Expand Up @@ -4608,6 +4609,7 @@ These are in alphabetic order, with the exception that the `Extended` versions o
+ isNew: `true` (boolean, required) - Whether or not this Property is new (will be created by publishing the Draft Form).

## Property Detailed (object)
+ name: `first_name` (string, required) - The name of the Property.
+ name: `the.age` (string, required) - The name of the Property.
+ odataName: `the_age` (string, required) - The name of the property as it will appear in OData. OData property names can only contain alphanumeric characters and underscores.
+ publishedAt: `2018-01-21T00:04:11.153Z` (string, required) - Publishing timestamp of the form that defined this property for the first time.
+ forms: (array[Form KeyValue]) - List of forms that create the property
2 changes: 2 additions & 0 deletions lib/model/query/datasets.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const { isEmpty, isNil, either, reduceBy, groupBy, uniqWith, equals: rEquals } =

const Problem = require('../../util/problem');
const { construct } = require('../../util/util');
const { sanitizeOdataIdentifier } = require('../../util/util');

////////////////////////////////////////////////////////////////////////////
// DATASET CREATE AND UPDATE
Expand Down Expand Up @@ -268,6 +269,7 @@ const getMetadata = (dataset) => async ({ all, Datasets }) => {
if (!propertiesMap.has(property.name)) {
propertiesMap.set(property.name, {
...property,
odataName: sanitizeOdataIdentifier(property.name),
forms: []
});
}
Expand Down
8 changes: 4 additions & 4 deletions test/integration/api/datasets.js
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ describe('datasets and entities', () => {
const asAlice = await service.login('alice');

await asAlice.post('/v1/projects/1/forms?publish=true')
.send(testData.forms.simpleEntity)
.send(testData.forms.simpleEntity.replace(/age/g, 'the.age'))
.set('Content-Type', 'application/xml')
.expect(200);

Expand Down Expand Up @@ -526,12 +526,12 @@ describe('datasets and entities', () => {
publishedAt.should.not.be.null();
return p;
}).should.be.eql([
{ name: 'first_name', forms: [
{ name: 'first_name', odataName: 'first_name', forms: [
{ name: 'simpleEntity', xmlFormId: 'simpleEntity' },
{ name: 'simpleEntity2', xmlFormId: 'simpleEntity2' }
] },
{ name: 'age', forms: [ { name: 'simpleEntity', xmlFormId: 'simpleEntity' }, ] },
{ name: 'address', forms: [ { name: 'simpleEntity2', xmlFormId: 'simpleEntity2' }, ] }
{ name: 'the.age', odataName: 'the_age', forms: [ { name: 'simpleEntity', xmlFormId: 'simpleEntity' }, ] },
{ name: 'address', odataName: 'address', forms: [ { name: 'simpleEntity2', xmlFormId: 'simpleEntity2' }, ] }
]);

});
Expand Down

0 comments on commit 8b7d8d0

Please sign in to comment.