Api-blueprint: توسيع هياكل البيانات

تم إنشاؤها على ١٢ نوفمبر ٢٠١٥  ·  6تعليقات  ·  مصدر: apiaryio/api-blueprint

مرحبًا ، لدي سؤال / اقتراح حول هياكل البيانات. ربما يكون هذا أكثر ارتباطًا بـ MSON ولكن سأبدأ هنا. للحفاظ على هياكل البيانات جيدة ومرتبة ، أرغب في أقل قدر ممكن من البيانات المكررة ، لذلك سيكون من الجيد أن تتوسع هياكل البيانات في بعضها البعض.

افترض بنية البيانات التالية:

# Data Structures

## Project_Link (object) 
+ self: `https://test.api.com/projects/5` (string, required)

## Project1_Get (object)
+ type: `projects` (string, required)
+ id: `5` (string, required)
+ attributes (object, required)
    + number: `PRO-5` (string) - A readable identifier for employees to refer to projects.
+ links (Project_Link, required)

في السمة links لـ Project1_Get أعيد استخدام الكائن Project_Link الذي يعمل بشكل رائع. لكن لنفترض أنني بحاجة إلى بنية البيانات التالية أيضًا:

## Project1_Identifier (object)
+ type: `projects` (string, required)
+ id: `5` (string, required)

يوجد الآن بيانات مكررة في هياكل البيانات الخاصة بي لأن Project1_Identifier يحتوي على السمة type و id ، ولكن أيضًا السمة Project1_Get تحتوي عليها. سيكون من الرائع أن أفعل ما يلي:

# Data Structures

## Project1_Link (object) 
+ self: `https://test.api.com/projects/5` (string, required)

## Project1_Identifier (object)
+ type: `projects` (string, required)
+ id: `5` (string, required)

## Project1_Get (Project_Identifier) <--- Extend!
+ attributes (object, required)
    + number: `PRO-5` (string) - A readable identifier for employees to refer to projects.
+ links (Project1_Link, required)

في المثال التالي ، يقوم الصياغة بإرجاع الأخطاء:

FORMAT: 1A
HOST: https://test.api.com/

# Test API
Hi, welcome to the API!

# Group Projects
Wow, we are using projects!

### Retrieve single project [GET /projects/{id}]
+ Parameters
    + id: `5` (string, required)

+ Response 200 (application/json)
    + Attributes (object)
        + data (Project1_Get, required)

# Data Structures

## Project_Link (object) 
+ self: `https://test.api.com/projects/5` (string, required)

## Project_Identifier (object)
+ type: `projects` (string, required)
+ id: `5` (string, required)

## Project1_Get (Project_Identifier)
+ type: `projects` (string, required)
+ id: `5` (string, required)
+ attributes (object, required)
    + number: `PRO-5` (string) - A readable identifier for employees to refer to projects.
+ links (Project_Link, required)
user<strong i="25">@development</strong>:/srv/www/docs$ drafter -v
v2.0.0-pre.1
user<strong i="26">@development</strong>:/srv/www/docs$ drafter --validate docs.md --use-line-num

error: (4)  base type 'Project1_Get' is not defined in the document; line 16, column 11 - line 16, column 40
warning: (8)  unable to find the symbol `Project1_Get` in the list of named types; line 16, column 11 - line 16, column 40
Language Parser Implementation Bug

التعليق الأكثر فائدة

robbinjanssen إذا كنت تريدهم أن يكونوا في القمة ، فيرجى فعل شيء مثل هذا:

## Project1Get
+ Include ProjectIdentifier
+ attributes (object, required)
    + number: `PRO-5` (string) - A readable identifier for employees to refer to projects.
+ links (ProjectLink, required)

ال 6 كومينتر

يجب أن يكون هذا ممكنا. يبدو أن المشكلة مع _ في اسم النوع. يبدو أن إعادة تسمية Project1_Get إلى X تعمل.

ملاحظة: _ محجوز لكل مواصفات MSON - راجع https://github.com/apiaryio/mson/blob/master/MSON٪20Specification.md#6- الأحرف المحجوزة - الكلمات الرئيسية

ومع ذلك ، أعتقد أننا نواجه خطأ هنا في تطبيق ccpksunkara

أنت على صواب ، وافق الصياغة الآن على تخفيض السعر باستخدام المثال التالي:

FORMAT: 1A
HOST: https://test.api.com/

# Test API
Hi, welcome to the API!

# Group Projects
Wow, we are using projects!

### Retrieve single project [GET /projects/{id}]
+ Parameters
    + id: `5` (string, required)

+ Response 200 (application/json)
    + Attributes (object)
        + data (Project1Get, required)

# Data Structures

## ProjectLink (object) 
+ self: `https://test.api.com/projects/5` (string, required)

## ProjectIdentifier (object)
+ type: `projects` (string, required)
+ id: `5` (string, required)

## Project1Get (ProjectIdentifier)
+ attributes (object, required)
    + number: `PRO-5` (string) - A readable identifier for employees to refer to projects.
+ links (ProjectLink, required)

لكنني أعتقد بالفعل أنه خطأ ، فكل من واجهة aglio وواجهة apiaryio تجعله خاطئًا:

screen shot 2015-11-12 at 11 14 41

تحرير: عفوًا ، أرى أن apiaryio يجعلها صحيحة! لكنه يضع النوع / المعرف في الجزء السفلي في هذه الحالة. أفضل وضعه في الأعلى.

سأنتظر قبل إعادة هيكلة مستنداتي مرة أخرى ؛-)

robbinjanssen إذا كنت تريدهم أن يكونوا في القمة ، فيرجى فعل شيء مثل هذا:

## Project1Get
+ Include ProjectIdentifier
+ attributes (object, required)
    + number: `PRO-5` (string) - A readable identifier for employees to refer to projects.
+ links (ProjectLink, required)

تضمين التغريدة

مثال بسيط على الخطأ هو كما يلي:

# GET /projects

+ Response 200 (application/json)
    + Attributes (object)
        + data (B_B, required)

# Data Structures

## A_A
+ a: a

## B_B (A_A)
+ b: b

zdne أعتقد أن هذا مرتبط بـ https://github.com/apiaryio/snowcrash/issues/335. ماذا تقول؟

هل كانت هذه الصفحة مفيدة؟
0 / 5 - 0 التقييمات